开发者

Jquery to load a page overrides my CSS

I'm using the line of jquery to load content into a div on my page

开发者_开发技巧
$('#divURLContent').load('http://myurl');

The problem is the CSS on the page I am loading overrides the CSS on the page it is loaded into. Is there a way to prevent this from happening?


It usually makes no sense to load a full page inside a DIV.

You should take care of rendering only a bunch of HTML in the server, without head or body, or select the part of content that you want to insert in the DIV.

In your case, the most simple thing you can do is:

$('#divURLContent').load('http://myurl body');

That will put in the DIV only the content inside the body tag of the loaded page.

Look at http://api.jquery.com/load "Loading Page Fragments" for more information.


Your best bet is to either redesign the page you're loading to only include the markup you wish to inject into the page rather than an entire page complete with CSS, or to lad the page with $.ajax instead of $.load and extracting the body's contents with jQuery before actually insertint it into the DOM. The former approach will reduce the amount of data you need to shift, the latter will degrade more gracefully as people will still see a page if they visit that page without going through AJAX.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜