html - What is the best way to hold data for jquery -
some time ago wrote quick jquery code select , advert @ random below
$(function () { var theimages = [ '*****.jpg', '******.jpg', '*****.jpg' ]; var thelinks = [ 'http://www.****.co.uk', 'http://www.****.co.uk', 'http://www.*****.co.uk' ] var therandomnumber = math.round(math.random() * (theimages.length - 1)); $("#ad1").attr('src','images/' + theimages[therandomnumber]); $("a#adl1").attr('href', thelinks[therandomnumber]); var therandomnumber2 = math.round(math.random() * (theimages.length - 1)); while (therandomnumber == therandomnumber2) { therandomnumber2 = math.round(math.random() * (theimages.length - 1)); } $("#ad2").attr('src','images/' + theimages[therandomnumber2]); $("a#adl2").attr('href', thelinks[therandomnumber2]); } ); </script>
i have code on 29 html pages in website. every time ad changes have change every page. can give advice on best , quickest way put parameters in have update 1 thing. of pages read these parameters , know display.
thanks paul
you should put javascript javascript (.js) file , include in each of html files so:
<head> <script src="/randomadvert.js" type="text/javascript"></script> </head>
Comments
Post a Comment