views:

62

answers:

3

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

A: 

Use .load()

Example:

$("#feeds").load("feeds.html");
Nimbuz
be careful, as this will load the whole html, including html and body tags which should not be repeated in a page ..
Gaby
scrap my above comment.. .load takes care of that .. (it only brings elements in the body tag..)
Gaby
+1  A: 

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.

kemp
This wouldn't work if "remote.page" was from a different domain would it?
Graza
when i tried this showing errori tried to load page from different domain
RSK
+1  A: 

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.

Paul Deen