Take the 2-minute tour ×

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.

share|improve this question

2 Answers 2

up vote 38 down vote accepted

For security reasons, you can only get the url for as long as the contents of the iframe, and the referencing javascript, are served from the same domain. As long as that is true, something like this will work:


If the two domains are mismatched, you'll run into cross site reference scripting security restrictions.

See also answers to a similar question.

share|improve this answer
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 Jun 2 '09 at 6:50
I was talking about the link you listed to the similar question. –  chris Jun 2 '09 at 6:50
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 Jun 3 '09 at 9:12

If your iframe is from another domain, (cross domain), the other answers are not going to help you... you will simply need to use this:

var currentUrl = document.referrer;

and - here you've got the main url!

share|improve this answer
-1 the OP is looking for the current url of the iframe, not the referrer of the parent page. –  Christophe Jun 10 at 20:43
@Christophe - I know, but it can help people looking for getting the main url and came to this question! –  ParPar Jun 11 at 5:08
gr8.. This helps me –  Vikky Jun 16 at 7:33

Your Answer


