Forum Moderators: open

Message Too Old, No Replies

Calling a Script from Another Page

I want JavaScript A's commands on A.html to reack JavaScript B on B.html

         

Descent_Fan

3:13 am on Sep 15, 2004 (gmt 0)

10+ Year Member



Hey guys, I'm new here and I come bearing questions.

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!

upside

6:38 am on Sep 15, 2004 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld! :)

JavaScript cannot access the properties of an iframe because it is a security violation.

Bernard Marx

7:49 am on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It can when it's from the same domain.

Descent_Fan

8:39 pm on Sep 15, 2004 (gmt 0)

10+ Year Member



Bernard Marx, pray tell more...

How do I make it so that it's on the same domain on my webserver (I doubt I can tho...)?

upside

8:54 pm on Sep 15, 2004 (gmt 0)

10+ Year Member



Bernard is correct. Descent_Fan, here is an example of two files at the same domain:

[example.com...]
[example.com...]

Bernard Marx

9:09 pm on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What upside means is that as long as they share the www.example.com (perhaps just example.com). They don't have to be in the same directory.

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.