Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Location
    Sutton-in-ashfield, Notts
    Posts
    117
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Loading exnternal pages into div

    I've been searching the net for a few hours now for a js that i can use <a href="http://www.sitename.com/#content/home">Home</a> load into a div, but i cant seem to find one, anyone got any ideas? or good links to any.

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Not a good idea.

    A full HTML page will have <html> and <head> and <script> and <style> and <body> tags that will not work if plopped into a <div>.

    You *might* get away with the <script> and <style> tags (but you might not! if they conflict with styles and script already in your page!) but the <html>, <head>, and <body> tags (and probably others) would be illegal and pure poison in the <div>.

    You *might* be able to strip out everything from the page except the text *between* (but no including) the <body> and </body> tags, but it could also be pure luck if it works.

    On top of all that, if the page uses JavaScript to do document.write() calls to create content, either that code will not be executed (so you don't get the content) or it will be executed, in which case the first document.write() will *WIPE OUT ALL EXISTING CONTENT* on the page!

    Finally, you can *NOT* do this if the page you are attempting to load is in another domain. That's not allowed. Period.

    You *COULD* load another site's page into a <frame> or <iframe>. You couldn't use JavaScript to inspect or alter the contents thereof (again, cross-domain scripting is not allowed), but at least you could load the page.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Location
    Sutton-in-ashfield, Notts
    Posts
    117
    Thanks
    7
    Thanked 0 Times in 0 Posts
    No it not if you dont put them in the external page.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,519
    Thanks
    77
    Thanked 4,381 Times in 4,346 Posts
    Well, sure... If *YOU* have control over all the external pages, then it's TRIVIAL!

    Code:
        var http = (window.XMLHttpRequest != null ) 
                 ? new window.XMLHttpRequest()
                 : new ActiveXObject("Microsoft.XMLHTTP");
        http.open( "GET", "urlOfSomeOtherPage.html", false );
        http.send( null );
        document.getElementById("SomeDiv").innerHTML = http.responseText;
    (That's doing the load synchronously. You could also do it async, with only a tiny bit more work.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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