views:

172

answers:

4

Hi. If this is my code, how do i set page1.html to show by default on page load?

Thanks in advance.

<head>
    <title>Test</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    function swapContent(targetID, url) {
        var target = document.getElementById(targetID);
 
        var ajax = new XMLHttpRequest();
        ajax.open('GET', url, true);
        ajax.onreadystatechange = function() {
            if(ajax.readyState == 4) {
                target.innerHTML = ajax.responseText;
            }
        }
        ajax.send(null);
    }
    </script>
</head>
<body>
    <div>
        <div>
            <a href="javascript: void();" onclick="swapContent('searchDiv', 'page1.html');">First</a> |
            <a href="javascript: void();" onclick="swapContent('searchDiv', 'page2.html');">Second</a> |
            <a href="javascript: void();" onclick="swapContent('searchDiv', 'page3.html');">Third</a>
        </div>
        <hr>
        <div id="searchDiv" style="width: 550px; height: 400px; overflow: scroll;">Please select one...</div>
    </div>
</body>
</html>
+1  A: 

If you want it to be loaded by javascript:

<body onload="swapContent('searchDiv', 'page1.html');"> 
jball
A: 

How about calling swapContent('searchDiv', 'page1.html'); in onload of the body tag?

klausbyskov
+1  A: 

You can add the onload event handler to thebody element:

 <body onload ="swapContent('searchDiv', 'page1.html');">
    ....

 </body>
Vincent Ramdhanie
+1  A: 

either put it in the onload event or depending on your framework you could include page1 inside the div in django it's

<div>{% include 'page1.html' %}</div>
RHicke