Reputation: 12860
For example, if I have an iframe that is set to google.com, then someone searches in the iframe, and it loads in the iframe. I want to have a link below the iframe that says something like "go to the page". When they click on it, it won't bring them necessarily to google.com, but to whatever page they are currently on in the iframe. I tried using the following code to no avail:
<iframe id=frame src="http://www.google.com" scrolling=yes></iframe>
<a id=moveOn href=# onclick='return false'>Click to go to page</a>
<script>
$('#moveOn').click(function(){
var src = document.getElementById('frame').contentDocument.location;
window.open(src);
});
</script>
Any suggestions? Thanks :)
Upvotes: 1
Views: 114
Reputation: 5857
The property contentDocument doesn't exist on some IE browsers. The code below should be better, however I didn't test it everywhere.
var src; if(document.getElementById('frame').contentDocument)src = document.getElementById('frame').contentDocument.location; else src = document.getElementById('frame').contentWindow.document.location
Upvotes: 1