Adding Javascript

Store UI, layout, design, look and feel; Discussion on the customer facing pages of your online store. Cascading Style Sheets, Themes, Scriptlets, NVelocity and the components in the ConLib directory.
Post Reply
ritchie85
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Thu May 15, 2008 3:00 pm

Adding Javascript

Post by ritchie85 » Sat May 17, 2008 11:10 am

I am trying to add javascript to a page that needs to be activated when the page loads. However I can't just add my own body tag as there is already one created by the program. Any idea how I can add my onload request to my page?

Thanks
Mark

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Adding Javascript

Post by jmestep » Sat May 17, 2008 4:54 pm

You could try putting it into the HTML Head field if it is for a particular category or product- I don't know if this will work or not.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Will
Captain (CAPT)
Captain (CAPT)
Posts: 263
Joined: Fri Oct 05, 2007 8:02 am

Re: Adding Javascript

Post by Will » Sat May 17, 2008 8:50 pm

For each function you want to call when the page loads, put this inside the HTML head tag:

Code: Select all

<head>
window.onload = function() {
yourFirstFunction();
yourSectionFunction();
}
</head>
Or, ideally, this would be contained in an external js file you reference in the head tag.

ritchie85
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Thu May 15, 2008 3:00 pm

Re: Adding Javascript

Post by ritchie85 » Tue May 20, 2008 9:56 am

Thanks for your help. It didn't work when I added it to the header of a content scriplet though. It just seems to ignore any scripting that I put in that box. I moved the script down into the body and it works now. I know that isn't the best of coding practices but it seems to be the only way I could get around it.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Adding Javascript

Post by jmestep » Tue May 20, 2008 10:28 am

Location of script- I've read a couple of things lately that mention putting the javascript at the bottom to help page performance. That way the content loads, even though the javascript might be slow.
http://www.stevesouders.com-- He is chief performance at Yahoo! and wrote a book "High Performance Web Sites"
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

Post Reply