Linked Questions

Popular Questions

How to call JS functions after loading the page in div

Asked by At

EDIT: I do not know if it is really needed, but some people cannot understand what is my problem and what do I ask. So, I am updating my question. I have 'index.html' with this code:

<!doctype html>
<html>
<head>
<meta charset="utf-8"> 
</head>
<body>
    <div id="navbar">
    <button onclick="loadurl('page2.html');">click me</button>
    </div>
<div id="mydata"></div>

<script>     
function loadurl(url) {
  var xhttp;
  if (window.XMLHttpRequest) {
    // code for modern browsers
    xhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("mydata").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", url, true);
  xhttp.send();
}


$(window).resize(function(){
var height = 20;  //take the header height
$('.content').css({'margin-top':height});  //alter the margin of the wrapped content
}).trigger('resize');  //trigger the margin resize when page is loaded
</script>
</body>
</html>

and 'page2.html' with this code:

<!doctype html>
<html>
<head>
<meta charset="utf-8"> 
<script type="text/javascript">
/*function init(){
 var gel_s = document.getElementById("1");
 gel_s.style.display = "none";
 var epal = document.getElementById("2");
 epal.style.display = "none";
 var gel_l = document.getElementById("3");
 gel_l.style.display = "none";
 var div_r = document.getElementById("4");
 div_r.style.display = "none";
}*/
</script>
</head>
<body onload="init()">

<center>
<p>some text.</p>
<div id="1">
<p>This is first div.</p>
</div>
<div id="2">
<p>This is second div.</p>
</div>

<div id="3">
<p>this is third div.</p>
</div>

<div id="4">
<p>this is fourth div.</p>
</div>

</center>
</body>
</html>

If you click the 'clickme' button, 'init()' is not called and all divs are visible. They should be hidden when the page is loaded and appear later accoring to user's choise. How can I call init() and hide them?

Related Questions