Forum Moderators: open
Let's suppose that I have A.html and a script on there. This script is:
function callB(variable)
{
popup = window.open("B.html", "title", "toolbar=0,status=0,menubar=0,scrollbars=0");
popup.document.frames['callA'].location.href = variable;
popup.document.close();
}
This script (in theory), should trigger a popup with URL "B.html". This HTML file has one key line that should intercept commands from the script back in "A.html", the script you just saw. This critical line is:
<iframe frameborder="0" src="about:blank" width=100% height=100% id=callA></iframe>
So theoretically I can insert the JavaScript into a document and click on a link that calls the function callB(variable), where "variable" is a URL. This action will pop up a popup (how appropriate) that will display "B.html" but also trigger the IFrame which calls on the "variable" specified by the function. The IFrame then directs itself to "variable" (the URL specified in the function).
This script works when I try it out on my computer, but it refuses to work on my webserver. What could be the problem?
Thanks for any input!
[example.com...]
[example.com...]
Here is, I believe, the cause of your worries..
Immediately after opening a window, you are attempting to reference the location object of a frame within the document of the window you have only just opened. The first link in that reference chain - the popup's document - hasn't loaded yet. Even then, the location object of it's contained frame may not yet be available.
When you do this locally, all the resources are near to hand so they are ready to query - but not when there's a few miles, routers and modems in-between.
There are ways to get around this (somewhere) - but it might be worth thinking about whether you need to do whatever you're doing the way you are doing it, or if there's another approach - overall.