Upload website to DIV

how do I really retrieve data from a website when writing a url in a text box, and then click submit. I want the data to be placed in the div that I have. Is it possible?

I tried with this, but it does not work!

<script type="text/javascript"> function contentDisp() { var url = $("#text").val(); $("#contentArea").load(url); } </script> <textarea id="text">Write URL here</textarea> <br /> <input type="button" value="Click" onClick="contentDisp();"> <div id="contentArea"></div> 
+4
source share
5 answers

Due to the sandbox on javascript calls, you cannot do this (you cannot call outside the domain from which JS was loaded), at least not directly

There are two methods.

The first would be to load the requested url into an iframe, not a div, setting the src parameter using JS. Simple, lightweight, but restricting access to data in an iframe.

The second would be to make an AJAX request on your server, and your server will then look at the URL and return the HTML content (quite easy to do with CURL or similar). This allows you to play a little with the returned content, but again, because of the sandbox for cookies, you will not be able to request something like a facebook page for users or anything that requires a session, since it will work through a server session and not a browser session.

+11
source

Given that it will not be able to perform logins or http authentication (so that you can use curl or another client-client), this one php file can be used as a proxy server for downloading content from other sites

 /* proxy.php */ <?php echo file_get_contents($_GET['url']);?> 

than assuming you place proxy.php in the same directory of the html page:

 $("#contentArea").load('proxy.php?url=http://example.com'); 
+7
source

Is the URL in the same domain as the page itself? For security reasons, most browsers do not allow AJAX requests on different sites. For more information on why see link text .

+1
source

That's right, browsers do not allow AJAX request to other sites in the domain, I had the same problem, and I made a hint to workmad3, something like this:

 $(document).ready(function(){ $('#url').change(function(){ var _url=$(this).val(); $('#webDisplay').attr('src',_url); }); }); 

where my url id is INPUT text, a very nice trick

0
source

1. Set up the load.php file on your server.

 <?php echo file_get_contents($_GET['u']); ?> 

2.in index.html .

 <script type="text/javascript"> function contentDisp() { var url = $("#text").val(); $("#contentArea").load('load.php?u='+url); } </script> 
0
source

All Articles