change window location when iframe location is changed
Is there a way to make it so that if the page inside an iframe is not the src, then it w开发者_如何学运维ill change the parent page to the url the iframe is trying to go to? Something like this:
<script>
function redir() {
if(document.getElementById("myiframe").src != 'http://www.google.com'){
window.location = document.getElementById("myiframe").location
}
}
</script>
<iframe src="http://www.google.com/" id="google" onload="redir()"></iframe>
No.
Per the same-origin policy, the parent page is not allowed to get any information about what's going in the iframe, unless the pages are on the same domain.
精彩评论