views:

1286

answers:

1

Is there a simple way to get the current URL from an iframe?

The viewer would going through multiple sites. I'm guessing I would be using something in javascript.

+1  A: 

For security reasons, you can't get the URL if the user has navigated the iframe away from the initial page and the iframe contents aren't within the same domain with the parent page. Within the same domain, you can get the URL with something like

document.getElementById("iframe_id").contentWindow.location.href

See also answers to a similar question.

kkyy
do you know if the solution provided by the winning answer works? I couldn't get it to work on my computer (IE, windows)
chris
I was talking about the link you listed to the similar question.
chris
There is no winning answer in the question I linked... if you mean the topmost answer, it isn't really a working solution. With IE, you could try the HTA approach provided also in the answers to the aforementioned question.
kkyy