Page 1 of 1

Error: Permission denied for <http://localhost>

Posted: Sat Nov 28, 2009 12:05 am
by rajdeep.paul
I am trying to get the innerHTML of a website which is loaded into a frame.I am using the following code:-

<?php
?>
<html>
<head>
<script type="text/javascript">
function getSrc(obj) {
alert(obj.src);
alert(window.frames["g"].document.getElementsByTagName("body")[0].innerHTML);
return obj.src;
}

</script>
</head>
<body onload="">
<a href="#" onclick="javascript:getSrc(document.getElementById('g'))">Get src</a></p>
<iframe id="g" name="g"
src="http://www.google.co.in/"
frameborder="0"
width="800"
height="600"
scrolling="yes">

</frameset>
<script type="text/javascript">

</script>
</body>

</html>



----------------------------------------------
my problem is that after clicking the "Get src", i am getting the url alert from the function getSrc(),but the second alert is not coming.The Error console of the browser displays an error like this:-

"Error: Permission denied for <http://localhost> to get property Window.document from <http://www.google.co.in>.Source File: http://localhost/sourceCode/login.php# Line: 13";

Can anyone fix this problem?or can suggest any other method to retrive the innerHTML from an iframe?

Re: Error: Permission denied for <http://localhost>

Posted: Sat Nov 28, 2009 3:06 am
by requinix
It's a security thing: your JavaScript can't interact with something that's on another site.

Do you have to do this entirely with JavaScript? Can't you use something like PHP's file_get_contents? Perhaps AJAX?