Loading Content into a Div From another domain

Brothers and Sisters out there in this vast kingdom we call the World Wide Web, i am in need of your help…:slight_smile:

okay, this is whats up, i wanna load a web page into a div tag, but the page is from another domain, its my domain but i set up a second domain for more space reasons. Now if i want to load this page into that div tag on my current domain page, how will i do so?

like have domain1.com with index.html and in index.html there is a div tag called “page” and when the page loads the other.html from domain2.com loads into this div tag called “page”

and i want it to show a loading.gif as like a preloader. I’ve googled this and got some stuff but it didn’t work, and im not sure if its because of the page being in a different domain.

You can use an iframe for this. But it sounds unnecessary - why do you want to load an entire page into a DIV tag? Why not just the content itself? Furthermore, what do you mean “space reasons”? How big is this second page? Even free webhosts give you several hundred MB…

As for the loading GIF, just use it as a background image on the DIV (i.e. use CSS). Then when the page iframe loads the content, it will simply cover it.

okay the loading make sense, and the space reason is cause i have to upload GB’s of videos that needs to be downloaded and the php file being loaded needs to be loaded in the domain1.com page

I checked the iframe thing and i even got a height calculate script, but it doesn’t seem to want to make the height the right size.

<script language=“JavaScript”>
<!–
function calcHeight()
{
//find the height of the internal page
var the_height=
document.getElementById(‘iFrame’).contentWindow.
document.body.scrollHeight;

//change the height of the iframe
document.getElementById(‘iFrame’).height=
the_height;
}
//–>
</script>

any reasons why?

iframe code :

&lt;iframe width="100&#37;" id="iFrame" 
onload="calcHeight()" 
src="http://www.domain1.com/Files.html" 
scrolling="no"&gt;
&lt;span class="special"&gt;This Page is loaded in an iFrame - 
If you can't see this it means your Browser does not support iFrames or is set not to accept them.
&lt;/span&gt;
&lt;/iframe&gt;

Your script won’t work because you cannot access the contentWindow property of an iframe when the content is from a different domain.

Why can’t you just define the height yourself?

<iframe height="400" width="500" src="page.html"></iframe>

Also please stop using [ quote ] for code, use the appropriate syntax highlighting:

[ highlight=“<language>” ]

code here

[ /highlight ]

without the spaces before and after the square brackets.

i want the whole page to display and the page has links inside of it that increases the size of the page, do u know how to resize a iframe with content from another domain?

or how to load it into a div tag?

do u know how to resize a iframe with content from another domain?

or how to load it into a div tag?

Yeah, with something like the code you used, but you can’t do it by measuring the size of the body element in the page inside the iframe - that can’t be done. You’re going to have to use a static height, or get it by some other method (which is likely to be messy or fragile).

It sounds like you need to re-think what goes on which server, as you’re getting yourself into a bit of a mess.

even if i have access to the current page on the other domain? other wise i will probably have to just load the page directly

I don’t understand what you mean. What do you mean by “access”? The browser doesn’t know or care that you own both domains. As far as the browser is concerned, domain1 is not to trust domain2.

Yes I know that, i mean isn’t there a javascript i can add in my page on domain2 that publishes the height of the page for an iframe, and then the information is gathered by another script on domain1 ??

But if it can’t then i’ll try alternative ways, thanks

No, because like I said, the script on domain1 cannot access anything at all about domain2. If it were to “publish” the height of the page somewhere, where would this be to? If it’s the same domain, then it’s still a problem.

This is why having these two domains seems like a terrible idea. Domains have nothing to do with “space”. Hosting is about space.

Still, if you’re intent on doing this, the only thing I can think of is to have the page on domain2 measure the height of the page, use Ajax to post this height to a text file on the same domain, and then use PHP on domain1 to access this file, via cURL or include() if you’ve set it to allow including things via URL. A truly ridiculous method for something seemingly trivial.