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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With