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
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.