I have an html page (test.html
) on my computer (localhost). In an iframe on that page I have abc.example.com
loaded.
I want to access the contents of the iframe abc.example.com
from another domain xyz.example.com
. Here is what I've tried so far:
//test.html in abc.example.com
<input type="textbox" />
<input type="submit" value="click_me" />
//Start.html in xyz.example.com
<script type="text/javascript">
$(document).ready(function() {
$("#ok").click(function() {
//using javascript
var oo = document.getElementById("myFrame");
document.getElementById("divFrame").innerHTML =
oo.contentWindow.document.body.innerHTML;
});
});
</script>
<iframe id="myFrame" src="http://localhost/exam/test.html"></iframe>
<div id="divFrame"></div>
<input type="submit" id="ok" />
But when I press the "ok" button, it throws an "Access is Denied"
error. I also get the same error when using jQuery to simulate clicks in the iframe:
var btn = window.frames[0].document.getElementsByName('click_me');
btn[0].click();