Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does alert('hello'); work in pageLoad() function?

Tags:

javascript

Alert does not work in pageLoad, why? thanks

<html>
<head>  
    <script type="text/javascript">
        function pageLoad()
        {
            alert('hello');
        }
    </script>
</head>
<body />
</html>

Problem found: Dave Ward suggests that since my page does not have a script manager (which calls PageLoad for me). that is the reason I was puzzled. I never realised I had to call it for myself when there was no script manager.

like image 907
Valamas Avatar asked Feb 24 '11 00:02

Valamas


People also ask

What is pageLoad function in JavaScript?

pageLoad() is a function that pages with an ASP.NET ScriptManager (i.e. MicrosoftAjax. js) will automatically execute after ASP.NET AJAX's client-side library initializes and then again after every UpdatePanel refresh.

How do I show alerts on page load?

JavaScript Alert: After Page Loads If you prefer to have the full page visible while the user reads the alert box message, use the onLoad event. To do this, place a function in the document's <head> , then trigger it using the onLoad attribute in the document's <body> tag.

How do you call a function on window onload?

window. onload = function() { yourFunction(param1, param2); }; This binds onload to an anonymous function, that when invoked, will run your desired function, with whatever parameters you give it. And, of course, you can run more than one function from inside the anonymous function.


1 Answers

Yes, but you need to invoke it somewhere:

<script type="text/javascript">

    function pageLoad()
    {
        alert('hello');
    }

    pageLoad();  // invoke pageLoad immediately

</script>

Or you can delay it until all content is loaded:

<script type="text/javascript">

    function pageLoad()
    {
        alert('hello');
    }

    window.onload = pageLoad;  // invoke pageLoad after all content is loaded

</script>
like image 184
user113716 Avatar answered Oct 10 '22 19:10

user113716