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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rajdeep.paul
Forum Newbie
Posts: 1
Joined: Fri Nov 27, 2009 11:56 pm

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

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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?
Post Reply