View Full Version : how use random content order for list that are in different html pages?

02-02-2013, 10:43 AM
Good morning,

after long research and stress finally i found the script that i needed to random my list on a website that i"m building for myself http://www.dynamicdrive.com/dynamicindex17/randomcontentorder.htm
I'm not a webmaster and i' not an expert about programming ect ect, also my English is very bad!

your script is working very well and it is exact what i needed.
The script is working on one page html where the list is! As i have more than one page with list how i can random for example the list from the page 2 to page 1. I try to be more clear. I try to build a b&b website. On the index page is starting the property list and there i have added the script and is working good the random content order. I have also page 2, page 3 with other property listened. My question is, how i can random all the property from different pages? example: The property X on page 2 have to going to page one, or page 3!

I hope i was clear but i'm not sure!

Thanks to every body for helping me!


02-02-2013, 05:43 PM
If all pages are to have the same random content this can be done with a session(browser) cookie or for a specified duration cookie.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<style type="text/css">
visibility: hidden;

<script type="text/javascript">

* Random Content Order script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code

function randomizeContent(classname,days){
var obj=randomizeContent.collectElementbyClass(classname),days=typeof(days)=='number'||days=='session'?days:-1,ck=randomizeContent.cookie(classname),ck=days=='session'||days>0?ck:false;
var nus=ck?ck.split(','):obj.nus.sort(function() { return 0.5 - Math.random(); });
var tbodyref=obj.ref[0].tagName=="TR"? obj.ref[0].parentNode : {};
for (var i=0; i<obj.ref.length; i++){
if (tbodyref.moveRow){ //if IE
// tbodyref.moveRow(0, Math.round(Math.random()*(tbodyref.rows.length-1)))
else {
document.cookie=classname+'='+nus+(typeof(days)=='number'?';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path=/':'');

var re=new RegExp(nme+'=[^;]+','i');
if (document.cookie.match(re)){
return document.cookie.match(re)[0].split("=")[1];
return null;

randomizeContent.collectElementbyClass=function(classname){ //return two arrays containing elements with specified classname, plus their innerHTML content
var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i"); //regular expression to screen for classname within element
var obj={};
obj.ref=[]; //array containing references to the participating contents
obj.text=[]; //array containing participating contents' contents (innerHTML property)
obj.nus=[]; //array containing the array numbers
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (var i=0; i<alltags.length; i++){
if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1){
return obj;


<div class="group1">
Content 1

<div class="group1">
Content 2

<div class="group1">
Content 3

<div class="group1">
Content 4

<div class="group1">
Content 5

<script type="text/javascript">

// parameter 0 = randomize order of contents with DIV class="group1"
// parameter 1 = the days persistence or 'session' (-1 = no persistence)