PDA

View Full Version : Loading Div from separate page in same domain into another page's div



Bomberman
29 Apr 2011, 01:24 PM
For a further explanation:
I want to load a div from my #news1 div in my recentNews page onto the homepage's div #latestnews.

recentNews.html

<div id="news1">
Title
Body
ect.
</div>

This will be pulled onto:

index.html

<div id="latestNews">
script here for pulling other div.
</div>

could anyone help me out with this? I'd prefer to use javascript atm because I don't have a server to test on.

MartinRinehart
01 May 2011, 05:09 AM
You run into XSS (Cross-Site Scripting) restrictions reading from / writing to separate pages, even when they are both in your own domain. The only way to avoid these entirely in JavaScript is when both pages are part of a single frameset (sorry, frames are deprecated so this is at best a short-term solution).

Using iframes will let you achieve the look, if not the fact, you want. Just open an iframe into page #2 inside a div on page #1.