I found this cool code for a banner rotator: <script language="Javascript"> <!-- // original content taken from Nic's JavaScript Page with permission // lack of these three lines will result in copyright infringment // made by: Nic's JavaScript Page - http://www.javascript-page.com var currentdate = 0; var core = 0; function initArray() { this.length = initArray.arguments.length; for (var i = 0; i < this.length; i++) { this[i] = initArray.arguments[i]; } } link = new initArray( "http://link1", "http://link2", "http://link3" ); image = new initArray( "http://image1.gif", "http://image2.gif", "http://image3.gif" ); text = new initArray( "Banner 1", "Banner 2", "Banner 3" ); var currentdate = new Date(); var core = currentdate.getSeconds() % image.length; var ranlink = link[core]; var ranimage = image[core]; var rantext = text[core]; document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>'); //--> </SCRIPT> Code (markup): But instead of using it inline I'd like to place it into a .js file as a function so I can call it from many different places in my blog, so I won't have to manually change every page when I want to change my banners/links. I've poked around at it but I'm just not a JS head and I keep stubbing my toes. If this is fairly easy can someone please show me the way? The code is working, I just need to wrap it up into a reusable file. Thanks.
Using this script you have to write this code in every page, because the script writes a code in the page. You can do it using DOM, but at that time you have to write a div element in the every page. So you have to write something in the every page!!!
Simple just take your code and save it to a new file eg.) code.js Remove the <script> and the </script> tag and then reference it like so in your head tag of your page(s) <script src="code.js" type="text/javascript"></script>
@FCM And what do you think about this row of code: document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>'); where the <a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a> will be written in the document?
Well just paste the <script src="code.js"></script> into a section where you want it to display it should work... I gave you an example for it to display on the top of the page. It doesn't matter where you put the code and where you put the code is where it will display so if you put the code in the footer it will display in the footer.
@FCM But the code has to be put in the every page, yes? And DGMarkets doesn't do it in the every page.
Every page that you want it to display on yes... If you don't want it to display then don't add it. It would be impossible to automatically add it to every page without using some form of content management system like Joomla
create a .js file with the below code in it. <!-- // original content taken from Nic's JavaScript Page with permission // lack of these three lines will result in copyright infringment // made by: Nic's JavaScript Page - http://www.javascript-page.com var currentdate = 0; var core = 0; function initArray() { this.length = initArray.arguments.length; for (var i = 0; i < this.length; i++) { this[i] = initArray.arguments[i]; } } link = new initArray( "http://link1", "http://link2", "http://link3" ); image = new initArray( "http://image1.gif", "http://image2.gif", "http://image3.gif" ); text = new initArray( "Banner 1", "Banner 2", "Banner 3" ); var currentdate = new Date(); var core = currentdate.getSeconds() % image.length; var ranlink = link[core]; var ranimage = image[core]; var rantext = text[core]; document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>'); Code (markup): then add (This code must be displayed on every page you want the javascript on!) <script type="text/javascript" src="your file name.js"></script> Code (markup): above </head> Code (markup):