Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript onload not working [closed]

I am using an external javascript file, which I am using to store all my javascript functions in. Next I am trying to call a function from the body, using the next line of code:

<body onload="imageRefreshBig()">

The only thing that this function does is making an alert box pop up, well that's what's it supposed to do. I know this is a rather easy question but I have been banging my head against a wall trying to find a problem/fix for this issue and nothing is working.

I also include the javascript file in my head:

<script type="text/javascript" src="javascript.js"></script>

But as you probably see this isn't working. Could anyone explain what is going wrong with my syntax/thinking. The only thing I could think of is that either my document is not being loaded properly or that I have a syntax error.

like image 709
Kipt Scriddy Avatar asked Jun 24 '13 11:06

Kipt Scriddy


3 Answers

You can try use in javascript:

window.onload = function() {
 alert("let's go!");
}

Its a good practice separate javascript of html

like image 107
Wilker Iceri Avatar answered Oct 05 '22 18:10

Wilker Iceri


Try this one:

<body onload="imageRefreshBig();">

Also you might want to check Javascript console for errors (in Chrome it's under Shift + Ctrl + J).

like image 29
Łukasz Dąbek Avatar answered Oct 05 '22 17:10

Łukasz Dąbek


There's nothing wrong with include file in head. It seems you forgot to add;. Please try this one:

<body onload="imageRefreshBig();">

But as per my knowledge semicolons are optional. You can try with ; but better debug code and see if chrome console gives any error.

I hope this helps.

like image 20
Shumail Avatar answered Oct 05 '22 18:10

Shumail