Alex Rivera | Logout

How to run JavaScript code before page load?

Asked 2011-08-04T15:18:52.753
32

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

I have tried:

<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.

Edit
Report

1 Answer

10

just insert a <script> tag wherever inside the body you want it to run. it will be executed as soon as the parser reads it, as long as it doesn't reference an element not yet created

answered 2011-08-04T15:22:03.353

Your Answer