473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mixing innerHTML and replaceChild - no good ...

What I've got:

1) a page with a "window.open('some_html', ...)"

2) "some_html" with basically this:

<body onload="document.body.innerHTML=FillIt('some_id')" ></body>

3) a script:

function FillIt(my_id) {
var inner = window.opener.document.getElementById(my_id).clone Node(true);

var a = document.createElement('a');
a.setAttribute('title', 'Close this window');
a.setAttribute('href', 'javascript:self.close()');
var img = document.createElement('img');
img.setAttribute('src', 'some_image');
img.setAttribute('alt', 'pop_down');
a.appendChild(img);

inner.replaceChild(a, inner.getElementById('popup'));
return inner.innerHTML;
}

This won't work. For sure I am doing something dumb in here (I'm a
newbie) but I think "innerHTML" just won't work with "replaceChild".

Please note there's only one 'popup' ID in my original DOM tree (it's
a table) and no, I'd not like to iterate on all the table elements just
to put it together in the end ...

Looking for some advise.
Thanks,

--
Michal Kurowski
<mk**@poczta.gazeta.pl>
Jul 23 '05 #1
3 3530
DU
MichaƂ Kurowski wrote:
What I've got:

1) a page with a "window.open('some_html', ...)"

2) "some_html" with basically this:

<body onload="document.body.innerHTML=FillIt('some_id')" ></body>

3) a script:

function FillIt(my_id) {
var inner = window.opener.document.getElementById(my_id).clone Node(true);

Why do you clone the node if you want to replace one of its child? I
don,t see your code (whole document) here, so I don't understand this.
var a = document.createElement('a');
I'd recommend to choose better identifiers when working with dynamically
DOM created elements. I personally use obj as a prefix or DOMobj.
a.setAttribute('title', 'Close this window');
It is known, recognized to avoid resorting to setAttribute when there is
already an DOM 2 HTML attribute which can be used. Often, such DOM 2
attribute will work much better.

a.title = "Close this window";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-78276800
a.setAttribute('href', 'javascript:self.close()');
a.onclick = new Function ("evt", "if(self.close()) {self.close();};");
var img = document.createElement('img');
img.setAttribute('src', 'some_image');
img.src = "some_image";
img.setAttribute('alt', 'pop_down');
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-95636861
a.appendChild(img);

inner.replaceChild(a, inner.getElementById('popup'));
inner is not the real node: inner is a copy, a clone of the node.

What was wrong with calling a function to do this in the opener, not in
the popup?
In the opener:
var objParentNode = document.getElementById("some_id");
(...your code here...)
and then
objParentNode.replaceChild(a, document.getElementById("popup"));
return inner.innerHTML;
}

This won't work. For sure I am doing something dumb in here (I'm a
newbie) but I think "innerHTML" just won't work with "replaceChild".

Please note there's only one 'popup' ID in my original DOM tree (it's
a table) and no, I'd not like to iterate on all the table elements just
to put it together in the end ...

Looking for some advise.
Thanks,


It's harder to see what could be wrong without seeing all the code and
what is involved in your window.

DU
Jul 23 '05 #2
DU
DU wrote:

a.setAttribute('href', 'javascript:self.close()');

a.onclick = new Function ("evt", "if(self.close()) {self.close();};");


This can not really work since the link has no href value. I'd suggest
to use a real button (an HTML button) instead since such current "link"
is a browser action, a browser command and not a resource to retrieve
and to load and then to code the onclick event. Like this:

var objButton = document.createElement("button");
objButton.type = "button";
objButton.onclick = new Function("evt", "if(self.close())
{self.close();};");
objButton.appendChild(document.createTextNode("Clo se this window"));

DU
Jul 23 '05 #3
DU <dr*******@hotwipethismail.com> wrote:

Why do you clone the node if you want to replace one of its child? I
don,t see your code (whole document) here, so I don't understand this.
OK, I was not clear enough, see below, please.
Cloning is just of the things I tried ...
It doesn't change much.

[snip]

Thanks a lot for info on W3C attribute names.
What was wrong with calling a function to do this in the opener, not in
the popup?
In the opener:
var objParentNode = document.getElementById("some_id");
(...your code here...)
and then
objParentNode.replaceChild(a, document.getElementById("popup"));

This will break the whole purpose of the thing.

What I try to do is to use an "onload" event in a new window to copy
the whole table from the opener. I'm sure it must be done in the new
window ...

How would you let it know about the "objParentNode" ?
Pehaps "window.opener" could be used in some other way ?

Thanks.

--
Michal Kurowski
<mk**@poczta.gazeta.pl>
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tim Fooy | last post by:
Hi all, I have the following problem. In my page i have a large <div> with tags inside it that have event handlers on them (onclick etc.). When i run div.innerHTML = moreText + div.innerHTML,...
3
by: Ralph Snart | last post by:
i've read that innerHTML is not in the W3C standards and never will be. however i've found something that i simply can't do by manipulating text nodes directly. <div id="mydiv"></div> <script...
1
by: Andrew Phillipo | last post by:
I have some code that works everywhere but IE5.0, including IE5.5. Here is a snippet of where the code seems to go wrong: Location.prototype.change = function(current) { this.current = current;...
9
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at...
1
by: biswaranjan.rath | last post by:
Hi, I'm facing problem after doing replaceChild for a DOCUMENT ELEMENT. Sample code: elem = document.getElementById( "myEle" ); var newVal; newVal = document.createElement('textbox');...
6
by: sonic | last post by:
Ok, i am sure everyone is sick of hearing about this. but i've checked about 10 different posts/sites about this issue, and they all say "use DOM" but i think there is more to be said. Perhaps I...
1
by: alexbf | last post by:
Hello, I'm trying to refresh some portions of a webpage using code like this : document.getElementById('tdGauge').innerHTML = document.getElementById('tdGauge').innerHTML; I do that...
4
by: sdustinh | last post by:
First, here is the code. function swapMP (theMPvalue) { if (theMPvalue !== "custom") { return; } var customMP = document.getElementById("part_mp"); var newCustomMP =...
6
by: cantrell78 | last post by:
I can't for the life of me figure out how to execute javascript inside of div that was set using innerHTML or in my case using cloneNode and replaceChild (not my idea to do this, I'm just fixing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.