jove
asked on
getting url of a sibling frame
I have a frame set containing two frames. Basically, what I want is the top frame to display the url that the bottom frame currently is showing. For example, if the bottom frame gets redirected to www.yahoo.com, then when I click on get URL in the top frame, it displays www.yahoo.com in the text field.
When I initially display the frame set (either as a local file or on a web server), it works, displaying something this: file:///D:/try.html (from file)
or: http://webserver/try.html (from web server)
But when I click a link at the bottom frame to www.yahoo.com, and call the getURL at the top frame, I get this:
Error: Access is denied. I get this whether I'm starting from a file or a web page.
The frameset html looks like this:
<HTML>
<FRAMESET ROWS = "105, *" >
<FRAME SRC='top.html' NAME="TopFrame">
<FRAME SRC='try.html' NAME="MainFrame">
</FRAMESET>
</HTML>
The bottom frame, try.html ("MainFrame") looks like this:
<HTML>
<BODY>
<A HREF="http://www.yahoo.com">Yahoo</A>
</BODY>
</HTML>
The top frame, top.html ("TopFrame") looks like this:
<HTML>
<BODY>
<A HREF="http://www.msn.com" onClick="return getURL();">get URL</A>
<FORM NAME="FORMA">
<INPUT TYPE="TEXT" NAME="INPUT1"></INPUT>
</FORM>
<SCRIPT LANGUAGE="JAVASCRIPT">
function getURL()
{
document.FORMA.INPUT1.valu e = parent.MainFrame.document. location;
return false;
}
</SCRIPT>
</BODY>
</HTML>
Again, I need a frame to be able to know the location/url of a sibling frame. Thanks in advance.
When I initially display the frame set (either as a local file or on a web server), it works, displaying something this: file:///D:/try.html (from file)
or: http://webserver/try.html (from web server)
But when I click a link at the bottom frame to www.yahoo.com, and call the getURL at the top frame, I get this:
Error: Access is denied. I get this whether I'm starting from a file or a web page.
The frameset html looks like this:
<HTML>
<FRAMESET ROWS = "105, *" >
<FRAME SRC='top.html' NAME="TopFrame">
<FRAME SRC='try.html' NAME="MainFrame">
</FRAMESET>
</HTML>
The bottom frame, try.html ("MainFrame") looks like this:
<HTML>
<BODY>
<A HREF="http://www.yahoo.com">Yahoo</A>
</BODY>
</HTML>
The top frame, top.html ("TopFrame") looks like this:
<HTML>
<BODY>
<A HREF="http://www.msn.com" onClick="return getURL();">get URL</A>
<FORM NAME="FORMA">
<INPUT TYPE="TEXT" NAME="INPUT1"></INPUT>
</FORM>
<SCRIPT LANGUAGE="JAVASCRIPT">
function getURL()
{
document.FORMA.INPUT1.valu
return false;
}
</SCRIPT>
</BODY>
</HTML>
Again, I need a frame to be able to know the location/url of a sibling frame. Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If this would work, it will only work once and maybe only for IE. Add a script to try.html that will handle the onClick event for the body. Once the event fires, pick up the event, determine the source and read the href property of the anchor???
not sure if this would work, I have never tried, but if the script worked, it could write the value of the href to the frameset file.
davlun
not sure if this would work, I have never tried, but if the script worked, it could write the value of the href to the frameset file.
davlun
ASKER
davlun,
I have not tried this, but in the real application I won't necessarily have access to the try.html (MainFrame) to incorporate javascript there. The real application uses a Web reporting tool that displays generated reports to the MainFrame, and I cannot modify the html output. I may, however, still try your suggestion just to see if it works. Thanks.
I have not tried this, but in the real application I won't necessarily have access to the try.html (MainFrame) to incorporate javascript there. The real application uses a Web reporting tool that displays generated reports to the MainFrame, and I cannot modify the html output. I may, however, still try your suggestion just to see if it works. Thanks.
Sorry, you could put that script in the frameset definition, the parent if you will.
reference by onClick="getURL()"
which will generate the anchor clicked and then pass that to the frameset page by parent.passURL(thisURL).
If you only need it once you will be ok, otherwise you are out of luck I think.
davlun
reference by onClick="getURL()"
which will generate the anchor clicked and then pass that to the frameset page by parent.passURL(thisURL).
If you only need it once you will be ok, otherwise you are out of luck I think.
davlun
Josh right, you can't access URL if the page is in the different domain.
Even if you follow suggestion to show
url of the clicked link, than it will work only when links are clicked in your frame. When user will click links in foreign site frame, this location changes wouldn't be reflected..
If this way is acceptable than,
instead of catching events on document level, you can do the following:
in your top frame add handlers to links
<script>
function getURL(link){
document.FORMA.INPUT1.valu e=link.hre f;
}
</script>
<A HREF="some.html"
onClick="getURL(this); return true;"
>some link</a>
This will be much more easy, and will work in NN3+, MIE4+ browsers.
Solution Tested with NN4, MIE5 (Win 32)
Even if you follow suggestion to show
url of the clicked link, than it will work only when links are clicked in your frame. When user will click links in foreign site frame, this location changes wouldn't be reflected..
If this way is acceptable than,
instead of catching events on document level, you can do the following:
in your top frame add handlers to links
<script>
function getURL(link){
document.FORMA.INPUT1.valu
}
</script>
<A HREF="some.html"
onClick="getURL(this); return true;"
>some link</a>
This will be much more easy, and will work in NN3+, MIE4+ browsers.
Solution Tested with NN4, MIE5 (Win 32)
ASKER
Thanks all. kollegov, the only reason I'm rejecting is because I would like to give the points to Josh, because he's the one that really answered it first.
ASKER
Thanks for the answer.
ASKER