Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery load body from external HTML

Tags:

I'm using jQuery and trying to load the body from an external HTML file.

It works if I try to load some div:

$('body').load('example.html #content');

But I'm unable to do something like this:

$('body').load('example.html body');

like image 666
Diogo Cardoso Avatar asked Mar 11 '11 09:03

Diogo Cardoso


People also ask

How do I put an external HTML page into 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 include HTML in jQuery?

Step 1: Firstly, we have to open that Html file in which we want to add the jQuery using CDN. Step 2: After then, we have to place the cursor between the head tag just before the title tag. And, then we have to use the <script> tag, which specify the src attribute for adding.

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.


1 Answers

From http://api.jquery.com/load

jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as <html>, <title>, or <head> elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.

Reading the above, it seems possible that your browser be only returning the body innerHTML. This obviously should be the same as requesting body, but maybe it's causing an error because body is not found?

I'd suggest trying a different browser.

like image 186
Adam Hopkinson Avatar answered Nov 02 '22 08:11

Adam Hopkinson