Load HTML page into another

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Duke

    Load HTML page into another

    <html>
    <head>
    <script type="text/javascript">
    function init(){
    var html = document.open(' Hello.html');
    document.getEle mentById
    }
    </script>
    <body onload ="init();">
    <did = 'hi'>
    </d>
    </body>
    </html>
  • Bart Van der Donck

    #2
    Re: Load HTML page into another

    Duke wrote:
    <html>
    <head>
    <script type="text/javascript">
            function init(){
                            var html = document.open(' Hello.html');
    document.getEle mentById
    Perhaps you meant:

    document.getEle mentById('hi'). innerHTML = html;
            }
    </script>
    <headshould be finished here. W3 requires a doctype declaration and
    a page title, too.
    <body onload ="init();">
            <did = 'hi'>
            </d>
    Perhaps you meant:

    <div="hi">
    </div>
    </body>
    </html>
    The open-method can't be used here. XMLHttpRequest is meant for that
    purpose.

    Putting it all together:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Demo</title>
    <script type="text/javascript">
    var xhr;
    function init() {
    xhr = null;
    if (window.XMLHttp Request) {
    xhr = new XMLHttpRequest( );
    }
    else if (window.ActiveX Object) {
    xhr = new ActiveXObject(' Microsoft.XMLHT TP');
    }

    if (xhr != null) {
    xhr.onreadystat echange = state_Change;
    xhr.open('GET', 'Hello.html', true);
    xhr.send(null);
    }
    else {
    alert('Your browser does not support XMLHttpRequest. ');
    }
    }

    function state_Change() {
    if (xhr.readyState == 4) {
    if (xhr.status == 200) {
    document.getEle mentById('hi'). innerHTML = xhr.responseTex t;
    }
    else {
    alert('Problem retrieving data:' + xhr.statusText) ;
    }
    }
    }
    </script>
    </head>
    <body onload="init()" >
    <div id="hi"></div>
    </body>
    </html>

    But there is an important objection! The content of the <divis now
    actually a full HTML-page inside another one. Though browsers might be
    "forgiving" , it's still invalid and quite dangerous design. The
    following variant is more healthy:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Demo</title>
    <script type="text/javascript">
    function init() {
    frames['hi'].location = 'Hello.html';
    }
    </script>
    </head>
    <body onload="init()" >
    <iframe name="hi"></iframe>
    </body>
    </html>

    Hope this helps,

    --
    Bart

    Comment

    Working...