views:

242

answers:

2

Is it possible to get the current URL that an IFrame is set to if it's loading an outside page (say, Wikipedia)? I've seen a few people say that it is impossible if it is not on your own server, but the places I've found that were 4 years old.

If it is impossible, is there an easier way to display a page inside another page and still have access to the url?

Thanks.

+8  A: 

It is impossible because of the same origin policy.

Trying to do that will result in an access denied message in a normal (i.e. "compliant") user agent.

I don't think there is an easy way to get around this, as this is one of the cornerstones of browser security.

Tomalak
A: 

Is this maybe what you are looking for?

<a href="#" onclick="document.getElementById('ifr').src = 'http://www.example.com'"&gt;click&lt;/a&gt;
Flavius Stef
I think what Tomalak said is what's my problem. Bummer.
GuyNoir
Yes, what he said is right. My point was that while you can't get the URL, you can still set it.
Flavius Stef