Jump to content

body onload to window.onload


brianlange

Recommended Posts

I have a complicated php page with javascript. It was having issue loading.

I moved the body onload to window.onload and the page is working better.

My boss seems to think this should be irrelevant but after 20 tests it appears to make a difference.

Has anyone had a similar issue? I know I am being vague and I cannot post code, I was just looking

for comments on issues with using the onload body property.

 

Link to comment
https://forums.phpfreaks.com/topic/261664-body-onload-to-windowonload/
Share on other sites

Being vague and saying things like "issue loading" and "make a difference" really doesn't help us understand what you're talking about. Or what we're supposed to do. Do you want anecdotes about using the onload event? Something more helpful?

If I had to guess at what is being asked, it seems like he is asking if there is a difference between:

<body onload="myfunction();">

and:

<script type="javascript">
window.onload=myfunction;
</script>

I personally haven't experienced any difference. I usually like to use the window.onload method so that I don't have to add anything more than I have to for the HTML code.

body onload was the way things were done in the early days of the internet, but markup (html), display (css), and function (javascript) are meant to be kept separate now. window.onload allows for onload functions to be kept in an external file, allowing for this separation. That alone is enough of a reason to be using it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.