Reputation:
I have the following code for jQUery to access the DOM inside of an iframe. But this does not work. What is the problem of the code? thanks
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
</script>
<script type="text/javascript" >
$(document).ready(function(e) {
$('#ifr').contents().find('div').click(function(event){
event.preventDefault();
console.log("this is a good thing");
});
});
</script>
<iframe id='ifr' style='width: 80%; height: 600px;' src='http://tarjom.ir'></iframe>
<div style="width: 200px;height: 100px; border: 1px red solid;">
</div>
Upvotes: 0
Views: 166
Reputation: 943097
The iframe has an absolute URI in the src
attribute. That implies you are attempting to access the DOM of a page on another domain. This is forbidden for security reasons.
Upvotes: 3