JavaScript Snippet doesn't work in text widget
-
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!
-
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.
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.
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
The plug-in for JavaScript / HTML etc. works, but my script doesn’t; however, that’s a separate issue.
The topic ‘JavaScript Snippet doesn't work in text widget’ is closed to new replies.