?
Solved

Navigate page to iframe url??

Posted on 2003-03-22
8
Medium Priority
?
3,652 Views
Last Modified: 2009-07-29
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.src
}

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['IFrameName'].location.href='http://www.cryer.co.uk/emily'">

Javascript:
<code>document.all.</code><code><em>IFrameName</em></code><code>.src='http://www.cryer.co.uk/emily'</code>

<p>

<input type="button"  value="Microsoft"
onclick="frames['IFrameName'].location.href='http://www.microsoft.com'">

Javascript:
<code>document.all.</code><code><em>IFrameName</em></code><code>.src='http://www.microsoft.com'</code>

<p>

<input type="button" value="Open Iframe wide" onclick="window.location.href =
window.parent.document.all.IFrameName.src">

Javascript: <code>window.location.href = window.parent.document.all.IFrameName.src</code>

<p>

<iframe SRC="test.html" name="IFrameName" width="100%" height="100" scrolling="no">

</body>
</html>


 
0
Comment
Question by:prob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:spo0ky
ID: 8189515
use this:

<input type="button" value="Open Iframe wide" onclick="window.location.href = window.IFrameName.location.href">

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
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 8189907
location.href=top.frames['IFramename'].location.href

Cd&
0
 

Author Comment

by:prob
ID: 8192017
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.IFrameName.src  ??
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 5

Expert Comment

by:cirtap
ID: 8192652
> 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
0
 
LVL 1

Expert Comment

by:spo0ky
ID: 8197560
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['IFrameName'].location.href='http://www.cryer.co.uk/emily'; i='http://www.cryer.co.uk/emily'">
<p>
<input type="button"  value="Microsoft" onclick="frames['IFrameName'].location.href='http://www.microsoft.com'; i='http://www.microsoft.com'">
<p>
<input type="button" value="Open Iframe wide" onclick="window.location.href=i">
<p>
<iframe SRC="test.html" name="IFrameName" width="100%" height="100" scrolling="no">
</body>
</html>
0
 
LVL 5

Accepted Solution

by:
cirtap earned 1000 total points
ID: 8204623
You can have a billion vars in your scripts, they would not help.
Whenever a page/script located in domain1 wants to access ANY information from a page/script located in domain2 you CANNOT access that information: it's blocked for security reasons. Period.
Some browsers have a bug in this (very well wanted) security mechanism that may allow a script - under special circumstances - to bypass its "sandbox", but you actually can't rely on them.

You may want to use ot for "good" reasons, but pleasy stress your mind think for half a minute about what may happen if a page from another domain (a banner maybe in an IFRAME) is able to read the FORM data from your login page or a purchase form that holds your CC number... I bet you do not want that to happen, right?

CirTap
0
 

Author Comment

by:prob
ID: 8207574
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?
0
 
LVL 5

Expert Comment

by:cirtap
ID: 8207712
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question