jQuery has a simple statement that checks the document
and waits until it's ready to be manipulated, known as the ready event. Inside the ready event you can add the code that you want to run right when the page is loaded.
<script type="text/javascript"> $(document).ready( function(){ //Your code here }); </script>
You can add this Javascript code in the head section of the template.php file or create an external Javascript file. If an external Javascript file is used make sure that it is added (inlcuded) in the head section of the template.php file. The following snippet shows how to include a Javascript file (template-welcome.js) located in the folder of the skin.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><? generateSystemName(); ?>: <? generateTitle(); ?></title> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> <? generateCSSIncludes(); ?> <? generateJavaScriptIncludes(false); ?> <script src="<? echo generateSkinLocation() ?>/template-welcome.js"></script> </head> <body> ... </body> </html>
The following could be the content of the Javascript file.
$(document).ready(function() { alert('hello world'); });