Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an external webpage into a div of a html page

Tags:

jquery

web

I need to load a responsive website into a div in my HTML page without using an iframe element.

I have tried this link; it's working for a single page URL, which I mentioned in the script.

$('#mydiv').load('http://localhost/qa/ask#external-div', function(response, status, xhr) {     if (status == "error") {         var msg = "Sorry but there was an error: ";         alert(msg + xhr.status + " " + xhr.statusText);       } }); 
like image 384
user2089987 Avatar asked Aug 09 '13 11:08

user2089987


People also ask

How do I put an external website inside a div?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.

How do you add another website to HTML?

Approach: To redirect from an HTML page to another page, you can use the <meta> tag by specifying the particular link in the URL attribute. It is the client-side redirection, the browsers request the server to provide another page.

How do I display HTML page from another HTML page?

HTML Iframe SyntaxThe HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.

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

Using simple html,

 <div>      <object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">     </object>  </div> 

Or jquery,

<script>         $("#mydiv")             .html('<object data="http://your-website-domain"/>'); </script> 

JSFIDDLE DEMO

like image 88
Optimus Prime Avatar answered Sep 20 '22 12:09

Optimus Prime


As mentioned in this stackoverflow thread, difference between iframe, embed and object elements

You can use <embed> tag, instead of <object> tag. If you require communication between child and parent.

† As pointed out in the comments below; scripts in <object> will run but the parent and child contexts can't communicate directly. With <embed> you can get the context of the child from the parent and vice versa. This means they you can use scripts in the parent to manipulate the child etc. That part is not possible with <object> or <iframe> where you would have to set up some other mechanism instead, such as the JavaScript postMessage API.

<embed type="text/html" src="snippet.html" width="500" height="200"> 
like image 27
Daniel Inbaraj Avatar answered Sep 19 '22 12:09

Daniel Inbaraj