How to run JavaScript function when web page is loaded

2 Answers

0 votes
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            function test()
            {
                alert('ok');
            }
            window.onload = test;
        </script>
    </head>
    <body>
            
    </body>
</html>

 



answered Nov 24, 2015 by avibootz
0 votes
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            function test()
            {
                alert('ok');
            }
        </script>
    </head>
    <body onload="test();">
            
    </body>
</html>

 



answered Nov 24, 2015 by avibootz
...