SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast Star777Star's Avatar
    Join Date
    Apr 2010
    Location
    South Africa
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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...

    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.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Enthusiast Star777Star's Avatar
    Join Date
    Apr 2010
    Location
    South Africa
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 :

    <iframe width="100&#37;" id="iFrame"
    onload="calcHeight()"
    src="http://www.domain1.com/Files.html"
    scrolling="no">
    <span class="special">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.
    </span>
    </iframe>

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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?
    HTML Code:
    <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.

  5. #5
    SitePoint Enthusiast Star777Star's Avatar
    Join Date
    Apr 2010
    Location
    South Africa
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    SitePoint Enthusiast Star777Star's Avatar
    Join Date
    Apr 2010
    Location
    South Africa
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Enthusiast Star777Star's Avatar
    Join Date
    Apr 2010
    Location
    South Africa
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  10. #10
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •