开发者

Are there any alternatives for an IFrame if I need to load an external url to my webpage

I need to know if there are any alternatives for an IFrame that I could use to load in an external URL into my webpage. Even 开发者_运维技巧if it's JQuery or JavaScript or PHP


You define a container in your page such as:

<div id="external"></div>

then you fill it with an AJAX call via jQuery:

$('#external').load("http://remote.page/");

EDIT: as pointed out by Graza in the comment, this won't work if the external page is on another domain due to the limitation on XMLHttpRequest objects -- if you need that you'll have to do a JSONP request, which requires cooperation on the server side. See this article for more information.


Be so careful doing this though, make sure you absolutely trust the 3rd party site. If they inject javascript into your page, it will be running under the same context as your own site, which could lead to all sorts of hackery followed by only tears and sadness. IFrames give you a certain amount of protection for this.


Use .load()

Example:

$("#feeds").load("feeds.html");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜