Ajax / jQuery - load the contents of a webpage into a div to load the page?

Without using iframes, content can be downloaded

<div id="siteloader"></div> 

With an external site, for example. somesitehere.com

When does the page load? - I know how to load contents from a file, but was not sure how to load the whole site?

Thank you very much,

+30
jquery ajax
Apr 01 2018-12-12T00:
source share
4 answers

This can do without an iframe . jQuery is used as it is mentioned in the title.

 <!doctype html> <html> <head> <meta charset="utf-8"> <title>Load remote content into object element</title> </head> <body> <div id="siteloader"></div><script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <script> $("#siteloader").html('<object data="http://tired.com/">'); </script> </body> </html> 
+48
Apr 01 2018-12-12T00:
source share

Take a look at the jQuery.load () function :

 <script> $(function(){ $('#siteloader').load('http://www.somesitehere.com'); }); </script> 

However, this only works in one domain of the JS file.

+35
Apr 01 2018-12-12T00:
source share

Using jQuery is possible, however, without using ajax.

 function LoadPage(){ $.get('http://a_site.com/a_page.html', function(data) { $('#siteloader').html(data); }); } 

And then put onload="LoadPage()" in the body tag.

Although, if you follow this route, the PHP version might be better:

 echo htmlspecialchars(file_get_contents("some URL")); 
+8
Apr 01 '12 at 11:00
source share

You cannot enter content from another site (domain) using AJAX. The reason iFrame is suitable for such things is because you can specify the source for another domain.

+2
Apr 01 2018-12-12T00:
source share



All Articles