PDA

View Full Version : Javascript: Display random text/banner on a web page (banner rotator)



Fli
06-24-2021, 01:03 PM
On one place you want to randomly display multiple versions of the text or image/banner and on next page load is displayed again random version of the text or image or code.



<script language="JavaScript">
// ==============================================
// Copyright 2004 by CodeLifter.com
// Free for all; but please leave in this header.
// ==============================================

var Quotation=new Array() // do not change this!

// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array. Remember
// to increment the Quotation[x] index!

Quotation[0] = "Version 1";
Quotation[1] = "Version 2";
Quotation[2] = "Version 3";

// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>


( replace Version 1,2,3 by your content, but beware of usage quotation marks " ' it can break the code, so you may need to either not use it or try commenting that out, maybe by \" or \' )