简体   繁体   中英

How to display html content using Javascript or jQuery?

Currently I use iFrame to display third party content. For example, my news page displays live website from CNN, MSNBC, Foxnews in single page.

Currently, I am just using iFrame to display those sites, but I was wondering if there is a better way to display the contents using Javascript, jQuery or other type of Javascript library?

Thanks

[edit] Is there a way I can compress the iframe and display it as a thumbnails without converting it to an image. Just shrink everything.

Currently, I am just using iFrame to display those sites, but I was wondering if there is a better way to display the contents using Javascript, jQuery or other type of Javascript library?

Hardly. You won't be able to fetch the content directly due to the Single Origin policy; and even if you were using a server-side proxy to circumvent this, every page is bound to be using a plethora of JS code incompatible with the others.

Having them all in separate iframed documents is the only way to go.

Due to the same origin policy , using iframes is necessary in this case. That is, unless of course you are writing something that simply runs on your local machine (as opposed to coming from a remote web server), then you can do whatever you want, such as loading the page with jQuery.get .

也许您可以使用YQL

Maybe those pages have rss? Then you can hook on to that, for instance using Google Feed API 2.

A lot of services offer JSON and JSONp apis that you can hook into. (I'd Google around for the docs) And once you have the data there are a number of JavaScript template libraries that you can use to insert the JSON data into the page: HTMLBuilder, PURE, Mustache, &c.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM