0

My script is running in an iframe in an iframe and I'm trying to get the root referrer (the url the iframe is on). It's not working. Here's the code:

<script type="text/javascript">
    var referrer_url = document.referrer;
    document.write("You come from this url: " +referrer_url);
</script>

Any ideas?

user1545275
  • 1
  • 1
  • 1
  • 1
    possible duplicate of [access parent url from iframe](http://stackoverflow.com/questions/3420004/access-parent-url-from-iframe) or http://stackoverflow.com/questions/115526/is-there-a-way-to-get-the-parent-url-from-an-iframes-content or http://stackoverflow.com/questions/3724969/get-the-parent-url-of-iframe-in-php or http://stackoverflow.com/questions/4413414/get-parent-location-url-iframe-from-child-to-parent – Manse Jul 23 '12 at 11:42
  • What do you mean by, "It's not working?" Do you get the wrong answer? Is it null? An error? vvv whoa good one :-) – Pointy Jul 23 '12 at 11:43
  • 1
    @Esailija It's the current economic climate. It's tough out there... – Lee Taylor Jul 23 '12 at 11:48

1 Answers1

2

Document.referrer doesn't get set on all occasions.

You should use window.top.location.href.toString(); but it requires that they both are on the same domain.

Silviu-Marian
  • 10,565
  • 6
  • 50
  • 72