Forums

[resolved] JavaScript Snippet doesn't work in text widget (5 posts)

  1. SirLucius
    Member
    Posted 7 months ago #

    The following code snippet does not work in my text wdiget on WordPress, is something wrong with my JavaScript? I've changed the URLs to xxx.com for this post:

    <SCRIPT LANGUAGE="javascript" TYPE="text/javascript>
    
    <!--
    
        // note: the 2nd image ("two") will be the first to appear in the animation
        // all images must be the same dimensions
        // works in NS 3, IE/NS 4+
        // other browsers or javascript disabled will see only the original image and link and no animation
    
        var has_loaded = 0;
    
        if (document.images) {
    
           one=new Image
           one.src="http://www.xxx.com/images/300x250ad1.jpg"
    
           two=new Image
           two.src="http://www.xxx.com/images/300x250ad2.jpg"
    
           three=new Image
           three.src="http://www.xxx.com/images/300x250ad3.jpg"
    
           four=new Image
           four.src="http://www.xxx.com/images/300x250ad4.jpg"
    
           five=new Image
           five.src="http://www.xxx.com/images/300x250ad5.jpg"
    
           has_loaded = 1;
        }
    
        go_URL = new Array();
           go_URL[0]="http://www.xxx.com";
           go_URL[1]="http://www.xxx.com";
           go_URL[2]="http://www.xxx.com";
           go_URL[3]="http://www.xxx.com";
           go_URL[4]="http://www.xxx.com";
    
        imgID = new Array();
           imgID[0]=one.src;
           imgID[1]=two.src;
           imgID[2]=three.src;
           imgID[3]=four.src;
           imgID[4]=five.src;
    
        var pause = 4000 // pause how long in milliseconds (1000 = 1 sec)
    
        var a = 0;
        var b = (go_URL.length - 1);
    
        function rotate(imgN) {
    
           if (has_loaded == 1) {
    
          if (a == b) {
         a = 0;
          }
          else {
         a++;
          }
    
          document.images[imgN].src = imgID[a];
          setTimeout('rotate("rotate_pic")',pause);
    
           } // end of if has_loaded
    
           if (window.status != '') { window.status = go_URL[a]; return true; }
        } // end of function rotate
    
        function goto_url() {
           if (document.images) {
          document.location=(go_URL[a]);
           }
           else {
          return false;
           }
        }
    
    //-->
        </SCRIPT>

    I really appreciate any help and ideas on how to fix it. Thanks!

  2. Christine
    Moderator
    Posted 7 months ago #

    I don't think that WordPress allows pasting of Javascript in posts, pages or widgets. You might need to add this code to your sidebar.php instead.

  3. SirLucius
    Member
    Posted 7 months ago #

    I found this plug-in : http://wordpress.org/extend/plugins/html-javascript-adder/

    Which allows me to enter JavaScript, HTML, etc. into a widget box.

  4. Christine
    Moderator
    Posted 7 months ago #

    Cool, let us know if that works and if it does, can you mark the thread as resolved so that others may also benefit from the answer?

    Cheers

  5. SirLucius
    Member
    Posted 7 months ago #

    The plug-in for JavaScript / HTML etc. works, but my script doesn't; however, that's a separate issue.

Reply

You must log in to post.

About this Topic