prob
asked on
Navigate page to iframe url??
We have a navigation system with tabs at the top which set the url of a large iframe underneath.
Within the iframes there are external links which open within the same iframe.
To 'break' out of the iframe, i navigate the page to the url of the iframe, ie
function SetPage()
{
window.location.href = window.parent.document.all .myFrame.s rc
}
Unfortunately, this function navigates to the default value of the iframe, not the current value.
How can I navigate to the current value of the iframe???
Here is an eg showing the problem.
Default.html follows, the iframe initally points to test.html
<html>
<body>
<p>
<input type="button" value="Emily"
onclick="frames['IFrameNam e'].locati on.href='http://www.cryer.co.uk/emily'" >
Javascript:
<code>document.all.</code> <code><em> IFrameName </em></cod e><code>.s rc='http://www.cryer.co.uk/emily'</code >
<p>
<input type="button" value="Microsoft"
onclick="frames['IFrameNam e'].locati on.href='http://www.microsoft.com'" >
Javascript:
<code>document.all.</code> <code><em> IFrameName </em></cod e><code>.s rc='http://www.microsoft.com'</code >
<p>
<input type="button" value="Open Iframe wide" onclick="window.location.h ref =
window.parent.document.all .IFrameNam e.src">
Javascript: <code>window.location.href = window.parent.document.all .IFrameNam e.src</cod e>
<p>
<iframe SRC="test.html" name="IFrameName" width="100%" height="100" scrolling="no">
</body>
</html>
Within the iframes there are external links which open within the same iframe.
To 'break' out of the iframe, i navigate the page to the url of the iframe, ie
function SetPage()
{
window.location.href = window.parent.document.all
}
Unfortunately, this function navigates to the default value of the iframe, not the current value.
How can I navigate to the current value of the iframe???
Here is an eg showing the problem.
Default.html follows, the iframe initally points to test.html
<html>
<body>
<p>
<input type="button" value="Emily"
onclick="frames['IFrameNam
Javascript:
<code>document.all.</code>
<p>
<input type="button" value="Microsoft"
onclick="frames['IFrameNam
Javascript:
<code>document.all.</code>
<p>
<input type="button" value="Open Iframe wide" onclick="window.location.h
window.parent.document.all
Javascript: <code>window.location.href
<p>
<iframe SRC="test.html" name="IFrameName" width="100%" height="100" scrolling="no">
</body>
</html>
location.href=top.frames[' IFramename '].locatio n.href
Cd&
Cd&
ASKER
Hmmm, neither suggestion works so far. I note the comment about the security restriction but surely you can get the url or scr of a document in an iframe?
Can we set the default scr of the iframe to its current value and then use window.parent.document.all .IFrameNam e.src ??
Can we set the default scr of the iframe to its current value and then use window.parent.document.all
> but surely you can get the url or scr of a document in an iframe?
NO you SURELY can't if the IFRAME and the script come from different domains - that's the point.
An IFRAME from the domain "microsoft.com" can't *read* from its parent in the domain "cryer.co.uk" and vice versa.
This is also true if one has the http: and the other https: protocol.
For both originating in the same domains the code from spoOky or Cd& would do.
CirTap
NO you SURELY can't if the IFRAME and the script come from different domains - that's the point.
An IFRAME from the domain "microsoft.com" can't *read* from its parent in the domain "cryer.co.uk" and vice versa.
This is also true if one has the http: and the other https: protocol.
For both originating in the same domains the code from spoOky or Cd& would do.
CirTap
Why can't you simply set a var, where you'll be always able to find the current address in the iframe. Like this:
<html>
<head>
<script language="javascript">
var i = "test.html"; // default src in the iframe
</script>
</head>
<body>
<p>
<input type="button" value="Emily" onclick="frames['IFrameNam e'].locati on.href='http://www.cryer.co.uk/emily'; i='http://www.cryer.co.uk/emily'">
<p>
<input type="button" value="Microsoft" onclick="frames['IFrameNam e'].locati on.href='http://www.microsoft.com'; i='http://www.microsoft.com'">
<p>
<input type="button" value="Open Iframe wide" onclick="window.location.h ref=i">
<p>
<iframe SRC="test.html" name="IFrameName" width="100%" height="100" scrolling="no">
</body>
</html>
<html>
<head>
<script language="javascript">
var i = "test.html"; // default src in the iframe
</script>
</head>
<body>
<p>
<input type="button" value="Emily" onclick="frames['IFrameNam
<p>
<input type="button" value="Microsoft" onclick="frames['IFrameNam
<p>
<input type="button" value="Open Iframe wide" onclick="window.location.h
<p>
<iframe SRC="test.html" name="IFrameName" width="100%" height="100" scrolling="no">
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I note cirtap's comments and will abandon this approach. Obviously what is happening now is that the default scr is being picked up by my function.
Does the same restriction apply to frames?
Does the same restriction apply to frames?
thanx for accepting these 'bad news' :)
> Does the same restriction apply to frames?
yepp. frame, iframe, popup-window, whatever contains an URI
you may only track the "new" URL once: when you change it and the i/frame goes off your domain (like your idea with the helper variable), but whatever happend inside this i/frame after that is inaccessible to your scripts.
although I've not tested this one: even an image comming from another domain should be inaccessible (eg. reading its .src, .width, .height)
All I could think of making other domain's content become "visual" part of your site is using a server side script on your domain that accepts a URL, gets that page (simulating a browser request) and forwards this content to your i/frame, NOW this page-copy originates from your own site, your server-script and your javascripts may access it (there are of coure other drawbacks here).
Note that this may violate copyrights etc. of the page owner.
Have fun
CirTap
> Does the same restriction apply to frames?
yepp. frame, iframe, popup-window, whatever contains an URI
you may only track the "new" URL once: when you change it and the i/frame goes off your domain (like your idea with the helper variable), but whatever happend inside this i/frame after that is inaccessible to your scripts.
although I've not tested this one: even an image comming from another domain should be inaccessible (eg. reading its .src, .width, .height)
All I could think of making other domain's content become "visual" part of your site is using a server side script on your domain that accepts a URL, gets that page (simulating a browser request) and forwards this content to your i/frame, NOW this page-copy originates from your own site, your server-script and your javascripts may access it (there are of coure other drawbacks here).
Note that this may violate copyrights etc. of the page owner.
Have fun
CirTap
<input type="button" value="Open Iframe wide" onclick="window.location.h
but it will work only if documents located in the iframe are your own (on the same domain), if not access to the location of those documents will be denited