Reputation: 1965
I have a simple form with post method. I am not sure why window.onload() function gets called twice below it shows up the page? Below is the code
function window.onload() {
initialisePage();
}
<form id="frmMain" method="post" runat="Server">
</form>
I tried using document.isready function before calling initialisePage didn't help.
Upvotes: 0
Views: 8204
Reputation: 4485
From the early 2000's I avoided using these types of hooks as they were undependable in these early days. Instead, I have always leaned on the tried and trued method of dropping in the 'init' call at the bottom of the page. It has never let me down.
...
<script>
body_loaded()
</script>
</body>
</html>
I know there are edge cases where this would not be ideal but it works 99.9% of usecases and follows 'KISS' principles.
Upvotes: 0
Reputation: 665
If window.onload gets called twice, means some changes are still happening on front side after initial load. A better to way would be by checking
window.onload = function() {
if(document.readyState == 'complete') {
myFunction();
}
};
Upvotes: 7
Reputation: 87203
SYNTAX ERROR in your code. onload
should be written as follow:
<script>
window.onload = function() {
initialisePage();
}
</scipt>
OR
window.onload = initialisePage; // Thanks to @nnnnnn
Upvotes: 1
Reputation: 408
You can use below line of code :
$(document).ready(function(){
initialisePage();
})
Upvotes: 0