View Single Post
Old 10-26-2011, 04:47 PM
Eugene Rimmer's Avatar
Eugene Rimmer Eugene Rimmer is offline
Senior Member
Join Date: Jan 2011
Location: Ecwid headquarters
Posts: 7,765

If you want any JavaScript code - including, but not limited to jQuery-based one - to run when a certain page in the product browser widget of Ecwid is open, you need to use the Ecwid JavaScript API , more exactly the OnPageLoaded event.

Thecode that needs to be executed should be wrapped into a function, and then the function needs to be added to the OnPageLoaded hadlers. Here is the example:
Ecwid.OnPageLoaded.add( // an Ecwid JS API call
  function(page) { // this is anonymous function constructed right in place, but you use the named functions as well
    alert('This code runs each time when a page is open inside an Ecwid product browser');
    // it is possible to react on different type of pages in Ecwid and their parameters
    if (page.type === 'PRODUCT') {
      alert('This code only runs when a product page is open');
    } else if (page.type === 'SEARCH' && page.keywords === 'foo') {
      alert('This code only runs when you search for a "foo" with a built in Ecwid search widget');
    // etc
    // of course it is possible to call jQuery inside this function too