views:

129

answers:

2

Hi There, I was hoping that someone can help me, I am trying to get the URL of a page in a iframe:

<script language="JavaScript">
    function myLocation() {
        alert(document.all.myFrame.contentWindow.location);
    }
</script>

<button onclick="myLocation();">Location of Frame</button>

<iframe src="http://www.google.com" width="800" height="600" frameborder="0"
                              scrolling="auto" name="myFrame"></iframe>

This basically will give me the location of the iframe in my page, but does not give me the google.com url - it is also important to give me the url of everypage that I may open from the google results, so when I am on google.com it should give me the google.com url and if I browse to www.facebook.com it should give me the facebook url...

Any ideas welcome! Thanks

A: 

you may want to use some sort of javascript library, but i've tried this code on deviantart.com using raw javascript code:

document.getElementsByTagName('iframe')[0].src and it gave me the result i was expecting.

Eimantas
This only gives the src of the initial page. It doesn't update when the document changes.
David Dorward
+3  A: 

The same origin policy prevents accessing details (including the current URI) of documents on other domains.

If you want to work around this, you will either need to use something other than a web page (such as a standalone application or browser extension) or proxy all requests through your own server.

David Dorward
yes @David proxying through own server is a better solution.
TheVillageIdiot