Results 1 to 2 of 2

Thread: how use random content order for list that are in different html pages?

  1. #1
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how use random content order for list that are in different html pages?

    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/dynamici...ntentorder.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!

    Camillo

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    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.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    .group1{
    visibility: hidden;
    }
    </style>
    
    <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 {
       obj.ref[i].innerHTML=obj.text[nus[i]];
      }
      obj.ref[i].style.visibility="visible";
     }
     document.cookie=classname+'='+nus+(typeof(days)=='number'?';expires='+(new Date(new Date().getTime()+days*86400000).toGMTString())+';path=/':'');
    }
    
    randomizeContent.cookie=function(nme){
     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){
       obj.ref.push(alltags[i]);
       obj.text.push(alltags[i].innerHTML);
       obj.nus.push(obj.nus.length);
      }
     }
     return obj;
    }
    
    </script></head>
    
    <body>
    <div class="group1">
    Content 1
    </div>
    
    <div class="group1">
    Content 2
    </div>
    
    <div class="group1">
    Content 3
    </div>
    
    <div class="group1">
    Content 4
    </div>
    
    <div class="group1">
    Content 5
    </div>
    
    
    <script type="text/javascript">
    
    // parameter 0 = randomize order of contents with DIV class="group1"
    // parameter 1 = the days  persistence or 'session' (-1 = no persistence)
    randomizeContent("group1",1)
    
    </script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Similar Threads

  1. Random Content Order issue in IE
    By Beachcomber in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 09-13-2012, 08:49 PM
  2. Random Content Order script help
    By justin-nc in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 10-04-2011, 11:17 PM
  3. Random Content Order script not so random?
    By robins in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 04-03-2009, 01:37 PM
  4. Random Content Order script - non-repeating random content
    By doomeyes in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-06-2008, 09:38 PM
  5. Random Content Order script
    By will_hough in forum Dynamic Drive scripts help
    Replies: 9
    Last Post: 11-13-2006, 04:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •