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

Discussion in 'PHP' started by rajdeep.paul, Nov 27, 2009.

  1. #1
    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?
     
    rajdeep.paul, Nov 27, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Nope. Its a security problem. Browsers does not generally allow Cross Domain iFrame content access. However there could be work around or tricks for few browsers.

    Little search on google might help, I could not search more but posting a link here for your referance.

    Google for iframe content read from other domain
     
    mastermunj, Nov 28, 2009 IP