Yashwant Kumar Sahu Yashwant Kumar Sahu - 5 months ago 27
Javascript Question

How to run java script code before page load?

I have working in asp.net web application. Here I need to run javascript before page load.

I have gone through

<body oninit="funinit();" onprerender="funRender();" onload="funload();">


</body>

<script type="text/javascript" language="javascript">
function funinit() {
alert("funinit");
}
function funload() {
alert("funload");
}
function funRender() {
alert("funRender");
}

</script>


here only funload() is working.
plz give me any solution to run script before page load.

Answer

You can use window.onpaint for such purpose like :

<script type="text/javascript">
    function preloadFunc()
    {
        alert("PreLoad");
    }
    window.onpaint = preloadFunc();
</script>

I hope it helps you....

Comments