tags:

views:

54

answers:

1

What are the best alternatives to iFrames with AJAX?

iFrames are not the best way to inject HTML into a website page that is on another site, I would love to know of a technology that does this, I prefer AJAX.

This iFrame will be on other peoples sites, so we don't have access to other users site, just the internal iFrame.

+1  A: 

If all you're looking to do is load some content from another page and insert it into your current page, I'd recommend using .load() from jQuery.

Assuming you want to load the content in an element with ID fragment, it would work something like this:

$('#fragment').load('some/page.html')

Note that this can only be used for pages from the same origin as your script. If you need to load pages across origins, iframe is the easiest way (though you don't get access to the inner page from the outer page).

In order for the AJAX example to work across domains, you could use CORS to allow requests between domains, but the page which is being included must explicitly allow itself to be included; you can't get arbitrary content from another domain.

Brian Campbell