Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I load webpage content into a div on page load?

Tags:

jquery

ajax

Without using iframes, is it possible to load the contents of

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

With an external site e.g. somesitehere.com

When the page loads? - I know how to load contents from a file, but wasn't sure how to load a whole site?

Many thanks,

like image 895
CodeyMonkey Avatar asked Apr 01 '12 10:04

CodeyMonkey


People also ask

How do you load a website into HTML?

You can use <embed> tag, instead of <object> tag.

How do I display content from another website?

You could use an <iframe> in order to display an external webpage within your webpage. Just place the url of the webpage that you want to display inside the quotes of the src attribute. Show activity on this post. Either you use an iframe or you load the site via AJAX into a div (e.g. using jQuerys load() method).

How do I show an external website inside another page without an iframe?

We can use the object tag in HTML to embed external resources in the webpage. We can use the tag to display another webpage in our webpage. The object tag is an alternative to the iframe tag in HTML. We can use the tag to embed different multimedia components like image, video, audio, etc.


2 Answers

This is possible to do without an iframe specifically. jQuery is utilised since it's 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> 
like image 104
Marcel Avatar answered Oct 18 '22 14:10

Marcel


Take a look into jQuery's .load() function:

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

However, this only works on the same domain of the JS file.

like image 44
faino Avatar answered Oct 18 '22 14:10

faino