views:

30

answers:

1

I'm trying to load the current page into an iframe in a subset of the page via javascript. If I set the src to another page it works fine, but setting the src to location.href (or the current url specifically) renders an empty iframe. Why is this occuring, and how can I correct this?

var my_Frame=document.createElement('iframe');
my_Frame.src = location.href;
document.body.appendChild(my_Frame); 
A: 

maybe try a proxy html:

<html>
    <head>
     <script type="text/javascript">
            function createIframe() {
                var my_Frame=document.createElement('iframe'); 
                my_Frame.src = location.search.substring(location.search.indexOf("href=")+5);
                document.body.appendChild(my_Frame);
            }
     </script>
    <head>
    <body onload="createIframe();"><body>
</html>

and redirect to proxy.html?href=[the location.href of the original page]

Roki
maybe i'm missing your approach here, but wouldn't the src return nothing here if the current URL doesn't have a query string? I can't control what URL this is going to be run on - it's from a bookmarklet
Red Collar