开发者

Grabbing Elements from Another Website using jQuery

WebPage1.html -> Contains my actual content

WebPage2.html -> Contains some elements I want to show on WebPage1.html

So according to the info above, how to grab elements from another page/domain/etc. show them on my page with jQuery?

I don't wa开发者_如何学编程nt to load entire page, just lets say only headers or a dropdown list or something else but only some parts.

I hope I express my questions exactly.

Thanks in advance.


What you're looking to do is a jquery ajax request. This page describes that API. You would then use jquery selectors to extract only the elements you wanted then modify your DOM in such a way as to display them.

While in most cases, @spender is correct about cross domain requests, this link might help.

This shows how you can perform an ajax call to your own server and have it grab (and hopefully santize/process) the response you want.

This is often thought of as a poor practice and if you state what problem you are looking to solve we may be able to give you better advice.


If WebPage2 lives in another domain, you can't do this.

If they are on the same domain, then you can create an iframe (possibly hidden), load the document there, examine it and copy the part that you want. This should get you started.

HTML has no way to partially load HTML documents. You either get everything or nothing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜