PDA

View Full Version : Detecting iframe location & opening iframe location in a new tab/window



k12onos
04-01-2012, 02:24 AM
Hi :)

I'm searching for a way to open the page inside an iframe in a new tab/window.

If let say my iframe content is initially google.com, then user cilcked (inside the iframe) the "images" link and then the iframe is directed to google.com/images.

I want a link on my page (outside the iframe) that allows them to open google.com/images in a new tab/window. This link would follow whatever the iframe content is. So even when they browsed to some random web page from my iframe, they can open that page in a new window by using that link.

Though i'm not going to be using this to let my users browse some random page on google in my iframe, I belive this analogy serves the purpose of explaining it :P


I tried to google it but I can't find a relevant answer.

Anyone can help me with this? Any answer or even pointers would be very much appreciated :)

jscheuer1
04-01-2012, 03:31 AM
You can't detect the iframe location unless both pages are on the same domain.

If they are, it's simple. Iframes are numbered from 0 to however many are on the page. So - say you just have one iframe:


<a href="#" onmouseover="this.href = window.frames[0].location.href;" target="_blank">Open Iframe Contents in a New Tab</a>

k12onos
04-01-2012, 04:31 AM
Exactly what I'm looking for! Luckily my iframe content is in the same domain. Thanks a lot! :)