w3schools:
Note: Because of security reasons, the contents of a document can be accessed from another document only if the two documents are located in the same domain.
If the containing page and the iframe/frame target belong to the same domain you can use this line:
alert(document.getElementById('myframe').documentWindow.location.href);