opener.document.getElementById("bgcolor").value = color;
opener.document.getElementById("xbgcolor").style.background = color;
After assigning the color to the 2 Id's, the popup window is closed. It worked perfect!
But now I want to use this code in an iFrame instead of a popup window.
But the code does not seem to work. Any one know how I can do the same thing in iFrame?
Don't use <!-- --> inside <script> tags.
Are you generating the iframe dynamically and do you want to remove it afterwards?
[B]parent[/B].document.getElementById("bgcolor").value = color;
[B]parent[/B].document.getElementById("xbgcolor").style.background = color;
Yes!! The iFrame is generated dynamically, then when the user chooses his color, the color is assigned to the variable, and the iFrame popup should be closed. Do you know how to dynamically close it?
By the way, why shouldn't I use <!-- --> inside <script> tags? I've seen this for many years to (I believe) hide the content from old browsers that doesn't support <script> .
Those comments can cause problems if you use XHTML and no usable browser needs them.
Some browsers may block iframe generation.
var ifr = parent.document.getElementById( "myIframe" /* or whatever its ID is */);
parent.document.getElementById("bgcolor").value = color;
parent.document.getElementById("xbgcolor").style.background = color;
ifr.parentNode.removeChild( ifr );
Netscape 2 came out in 1996, so the <!-- --> tags around script content on the page is only if you have inline scripting on your web page, which you shouldn't be doing, or if you are providing compatibility for web browsers that were around before 1996, which you shouldn't be supporting.
tl;dr Don't use <!-- --> in your scripts
This topic is now closed. New replies are no longer allowed.