<body onLoad="javascript:myfunction()" >But what if you don't have access to change the onLoad()? Is there an answer for that as well?
Yes, and it's easy. Just call the function inside your page as same as you would write JavaScript inside the body of a page.
<script type="text/javascript" language="JavaScript">
doSomething('params');
</script>
In this example, doSomething() function is added to the web page inside the header of the page. And for ease of understanding the complete code is shown below.
<html>
<head>
<script type="text/javascript" language="JavaScript">
function doSomething(params);
//do something nice with params
}
</script>
</head>
<body>
This page does call a JavaScript function when the page is loaded,
without using the onload() event call.
<script type="text/javascript" language="JavaScript">
doSomething('blue');
</script>
</body>
</html>
Thanks. I was looking for this.
ReplyDeleteThanks. It helped me a ton!
ReplyDeleteShouldn't it be function doSomething('params'){ in the head section?
ReplyDeleteThanks, though. Was looking for this...as well.
What if the function needed to manipulate an object in the document.? We know that the object is in the body which hasn't been loaded yet.
ReplyDeletetnnks a ton......i am extremenly happy after getting this code...thnx a ton ton ton..once again
ReplyDeletethnx a ton....i was glad after getting this code..thnx once again
ReplyDeleteno it doesn't
ReplyDeletewhy it does not work for me? what i am doing wrong?
ReplyDeletethanx a lot for the info :)
ReplyDeletethanx a ton for the suggestion ... was of great help
ReplyDeleteyes very helpful and concise info.
ReplyDeleteThis helped me a ton. Could not understand why my textbook instructions were not working.
ReplyDeleteThanks Thanks thanks.
Thanks! Concise answer to a silly/annoying question
ReplyDeletenice work dude..
ReplyDeletethanks..
nice...
ReplyDeletethanks dude
Thanks for the tip!
ReplyDeletethanks it helped me a lot
ReplyDeletethanks it helped me a lot
ReplyDelete