Results 1 to 10 of 11

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,374
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    Quote Originally Posted by misty View Post
    Thanks for answer but I was aware of that thread and in fact implemented that solution in my website.
    I am looking for a better solution, according to Zen Cart guidelines for javascript.
    The mentioned files should not be hacked into, there is an unobtrusive way to do this, set forth in the docs and in the Wiki.
    I managed to do the header part, but the body part is proving elusive because it involves an on_load() function.
    I need help with that.

  2. #2
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Loading a javascript site-wide

    Depends on the script you are using, for example if you are using a js framework such as jquery or mootools you dont need to insert the code to onload at all. For jquery, you can use $(document).ready(){//code here}
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  3. #3
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,374
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    Quote Originally Posted by yellow1912 View Post
    Depends on the script you are using, for example if you are using a js framework such as jquery or mootools you dont need to insert the code to onload at all. For jquery, you can use $(document).ready(){//code here}
    Hey yellow,
    Obviously, you are super multi-tasking.
    Actually, this is simpler than that.
    I want to update the mod. for installing a Comodo Corner of Trust.
    So far, this has been done by hacking into the files.
    You can see the solutions that have been implemented by clicking on the link that misty provided.
    That solution is incorrect and doesn't follow the guidelines for javascript in Zen Cart.
    You should be able to load these scripts dynamically and unobtrusively, i.e. without modifying core Zen cart files at all.
    I have achieved this for the header part, by loading the following in includes/templates/CUSTOM/jscript/jscript_comodocorner.js
    //<![CDATA[
    var cot_loc0=(window.ocation.protocol == "https:")? https://secure.comodo.net/trustlogo/javascript/cot.js" :
    "http://www.trustlogo.com/trustlogo/javascript/cot.js";
    document.writeln('<scr' + 'ipt language="JavaScript" src="'+cot_loc0+'" type="text\/javascript">' + '<\/scr' + 'ipt>');
    //]]>
    that's how I got rid of the hack to html_header.php.
    Please note that I used the Zen Cart convention: there are no <script> tags, Zen Cart will put them in for you.
    Also, the file has to be named in a certain way: jscript_XXX.js
    Now, I am looking for help on the body part.
    I know that within same jscript folder I have to create another on_load folder and put in there a file named on_load_comodocorner.js
    This file has to have an on_load function (which can be called anything you like, of course).
    This is what this function needs to load:
    <a href="http://www.instantssl.com" id="comodoTL">SSL</a>
    <script language="JavaScript" type="text/javascript">
    COT("images/cornertrust.gif", "SC2", "none");
    </script>
    So here are my questions:
    1) Should I leave off the <script> tags?
    2) How do I load the anchor tag?
    A suggestion on how to write the function would be much appreciated.
    Thanks for the great support.

  4. #4
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,374
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    var cot_loc0=(window.location.protocol...
    Typo in previous post, sorry.

  5. #5
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Loading a javascript site-wide

    For the <a>, I believe you have to put in in your code, just some where in your template code.
    Or you can write a piece of code that append that to an element on your page '<a href="http://www.instantssl.com" id="comodoTL">SSL</a>'

    I would go for the 1st choice since it's easier

    For the second part, I never tried the body_onload but I dont think you need to put the script tag there if the file is .js. You only have to put the script tag if the file is .php (you can put .php files in the jscript folder)
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  6. #6
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,374
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    Quote Originally Posted by yellow1912 View Post
    For the <a>, I believe you have to put in in your code, just some where in your template code.
    Or you can write a piece of code that append that to an element on your page '<a href="http://www.instantssl.com" id="comodoTL">SSL</a>'
    I would go for the 1st choice since it's easier
    For the second part, I never tried the body_onload but I dont think you need to put the script tag there if the file is .js. You only have to put the script tag if the file is .php (you can put .php files in the jscript folder)
    Hey yellow,
    Thanks indeed for quick answer.
    Don't want to pester you very much.
    Just a couple q.:
    I know it would be easier to just hack the files as has been done so far, I did it myself and it works, but it doesn't look good and makes upgrades more difficult.
    The whole point is to leave them files alone.
    -------------------------------------
    Or you can write a piece of code that append that to an element on your page '<a href="http://www.instantssl.com" id="comodoTL">SSL</a>'
    -------------------------------------
    How would I append that anchor tag?
    What would be the syntax?
    I cannot use document.write()...
    Regarding the second issue, will try it both ways.
    Probably you are right and no script tags are needed.
    It's testing time!

  7. #7
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Loading a javascript site-wide

    When you edit the template file, it is not considered hacking in the code (obviously you do have to edit those files to change your template anyway).

    The reason why I did not give the specific code because such code can have unexpected behavior on different browsers, so I usually do it using jquery or some other frameworks (which take care of the compatibility issue for me)

    Also, after looking closely at your code, you may not even have to put it in the body onload, you can put that whole thing at the bottom of your page as well.

    Code:
    <a href="http://www.instantssl.com" id="comodoTL">SSL</a>
    <script language="JavaScript" type="text/javascript">
    COT("images/cornertrust.gif", "SC2", "none");
    </script>
    Some may argue that it's not good to do so, but if you have GoogleAnalytics or AdSense on your page you do the same thing anyway.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

 

 

Similar Threads

  1. Javascript not loading on Checkout pages
    By tcarden in forum General Questions
    Replies: 3
    Last Post: 25 Mar 2014, 06:43 PM
  2. Implement site wide javascript
    By usr50 in forum General Questions
    Replies: 7
    Last Post: 26 Feb 2011, 03:50 AM
  3. Half Frozen loading stuck site with text only loading
    By Zellcorp in forum Installing on a Windows Server
    Replies: 5
    Last Post: 1 Nov 2009, 09:16 AM
  4. Loading javascript files - prototip
    By guls_guys in forum General Questions
    Replies: 1
    Last Post: 19 Jun 2008, 12:40 PM
  5. Site Wide Javascript
    By traders in forum Templates, Stylesheets, Page Layout
    Replies: 14
    Last Post: 18 Nov 2007, 03:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg