Load external html file

Discussion in 'JavaScript' started by Kuna, Sep 26, 2009.

  1. #1
    Can someone please explain me how to load external html (e.g. test.html) into index.html?

    test.html contains links, div, css and its own javascript code.

    I tried this http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm but it doesnt work. I can load external html file but it loads only css, links and div, not javascripot code which is attached to that file
     
    Kuna, Sep 26, 2009 IP
  2. Justin_Timberlake

    Justin_Timberlake Guest

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can use iframe or php include functions..
     
    Justin_Timberlake, Sep 26, 2009 IP
  3. Kuna

    Kuna Well-Known Member

    Messages:
    426
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    I tried iFrame, not good enough. But I need multiple file to load
     
    Kuna, Sep 26, 2009 IP
  4. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    why exactly is iframe not good enough? You might want to describe what you want to do so we can help you. Just showing one HTML page within another is exactly what an iframe does.
     
    ThomasTwen, Sep 26, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    IFrame is probably the only option or the CSS from all the different pages will change the appearance of the original page.. most likely. Otherwise you could use server-side includes.
     
    camjohnson95, Sep 27, 2009 IP
  6. Jj delc

    Jj delc Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Have you tried using a Js framework, with Jquery you could simply do:

    $('#thisdiv').load('text.html');

    For javascript, you should keep that in a separate script file (it's a good practice), again with JQuery you can load that dinamically using $.getScript('myscript.js')
     
    Jj delc, Sep 27, 2009 IP