How do I call a JavaScript function before the end of the body of an HTML page?
+2
A:
<html>
<head>
<script...>
function helloWorld() {
alert('Hello world!');
}
</script>
</head>
<body>
...some content...
<script...>
helloWorld();
</script>
</body>
</html>
Max
2010-06-22 10:57:42
thanks a lot!!!!!!!
Lalchand
2010-06-22 11:01:19
+3
A:
You can just place a <script>
block in there, like this:
<script type="text/javscript">
myFunction();
</script>
</body>
Also, if you're using a framework of some sort, most of them have handlers for when the DOM is ready, or you can use window.onload
, whatever best fits your situation.
Nick Craver
2010-06-22 10:58:04