views:

322

answers:

2

So I've found some stuff online but none of it uses jQuery and most of it is old and not suited for what I'm doing.

I have a main page and then a div overlay. Something like www.bacolicious.com, but with a little x bar and links :D

I had some old code that may have been working at some point, at least someone put it in.

window.open($('iframe').attr('src'), "_self");

However what this does is just always redirect to whatever I set src to in the beginning. The scr attribute doesn't seem to change which is the problem. I was thinking of setting my links to manipulate the src tag but this won't help if someone browses to say, youtube and then watches a few movies and presses the button to click out.

A: 

You can retrieve the current location of the iFrame with:

var iFrameHref = document.body.getElementsByTagName["iframe"][0].location.href;
window.open(iFrameHref,"_self");
Chris Pebble
A: 

Whilst you can read an iframe's current location using:

var iframe= document.getElementById('myiframe');
var idoc= ('contentDocument' in iframe)? iframe.contentDocument : iframe.contentWindow.document;
var src= idoc.location.href;

this won't help if someone browses to say, youtube

...if someone browses to a site that is not your own, you may not read the address or any other properties of the document in the iframe, due to Same Origin Policy security restrictions.

If you want to track and fiddle with the document the user is browsing, you have to do it as a rewriting proxy.

bobince