Zen Cart Logo
Forums / General Questions / another on_load jscript question

another on_load jscript question

Views: 702

Results 1 to 2 of 2
20 Jan 2012, 5:21 PM
#1
simon1066 avatar

simon1066

Totally Zenned

Join Date:
Feb 2009
Location:
UK
Posts:
1,326
Plugin Contributions:
0

another on_load jscript question

Running v1.50 - on a local server, and read the following recommended resources to try and get 'on_load' to work:

Documents in the Zen Cart default install package.
docs/read_me_jscript.html
docs/read_me_onload.html

And more in the wiki
Javascript

I have successfully added an image slider to the main page of my site by:

adding** jscript_jquery.nivo.slider.js** into includes\templates\MY_TEMPLATE\jscript folder

adding stylesheet_nivo-slider.css into includes\templates\MY_TEMPLATE\css folder

added a <div> in tpl_main_page.php calling up the images to use in the slider (probably shouldn't have used this file but included 'if($this_is_home_page)', and it seemed a good idea at the time).

added the following code, after the above <div> :

<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider();
});
</script>

and, included in html_header.php this code

<link rel="stylesheet" href="stylesheet_nivo-slider.css" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="jscript_jquery.nivo.slider.js" type="text/javascript"></script>

I have left the external link to jquery.min.js whilst testing.

All seems to work ok.

Rather than having the code in html_header.php I wanted to use the on_load system. So I created a file on_load_nivo.slider.js in includes\templates\MY_TEMPLATE\jscript\on_load\ folder with exactly the following code:

<link rel="stylesheet" href="stylesheet_nivo-slider.css" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script src="jscript_jquery.nivo.slider.js" type="text/javascript"></script>

deleted the code I had inserted in html_header.php and expected it to work. No joy

Any ideas as to what I have done wrong?

20 Jan 2012, 11:06 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: another on_load jscript question

The on_load "system" to which you refer doesn't load a bunch of HTML such as you're proposing. It simply inserts a statement to appear inside the <body> tag's onload="xxxxx" attribute.

You're stuffing HTML into a .js file. They're completely different animals.

The stuff you're putting in your on_load_nivo.slider.js file is probably best put into an /includes/templates/your_template/jscript/jscript.nivo.php file instead.

In my estimation this issue has nothing to do with on_load at all.