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?
Error: Permission denied for <http://localhost>
Moderator: General Moderators
-
rajdeep.paul
- Forum Newbie
- Posts: 1
- Joined: Fri Nov 27, 2009 11:56 pm
Re: Error: Permission denied for <http://localhost>
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?
Do you have to do this entirely with JavaScript? Can't you use something like PHP's file_get_contents? Perhaps AJAX?