For security reasons, you can get the URL as long as the contents of the iframe and the referenced javascript are in the same domain.
If so, you can do something like:
document.getElementById("frameid").contentWindow.location.href
If these two domains are different from each other, you will get all the restrictions that apply to the domain with reference to the intersite link . Example:
document.getElementById("frameid").src = 'http://www.google.com/'; alert(document.getElementById("frameid").documentWindow.location.href); Error: Permission denied to get property Location.href
Of course (if a big security flaw is detected in your browser), you simply cannot achieve what you need using javascript in the parent document. Let's see with a simple example why. If the browser has resolved what you need, you can easily:
- Create a page with a hidden iframe (e.g.
http://malicous.com/dont-trust ) - In this iframe, open a child page with the process of logging into a website (for example,
http://insecure-web-site.com/redirectlogin ) - If cookies for the child are present and under certain circumstances, the page inside the frame will be redirected to the real website, while continuing to log on to the user.
- Now, from the parent page, you can read all the confidential information that goes through the login process contained within the URL, for example. access tokens, session identifiers, ...
- At this stage, the victimβs site and its users face a wide new set of possible security threats ...
source share