Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question CMS Search Results w/Random Javascript

    Hi everyone,

    My first post here; please bear with me! I've looked through quite a few posts re: random # returns in the forum and came up with quite a bit of info, but I'm still a bit unsure of how to apply what I've read to my situation.

    I'm using content management software to build a site for a nonprofit artists group. Each artist has their own page w/samples of their artwork. In order for an easy way to click from one artist page to the next, I needed a "next artist" button to be automatically generated by the CMS. This could only be done by coding a page to return search results for the Artist Index. I limited the results to 1 per page, and viola. And easy way to view all of the artists in the group.

    The area I'm talking about

    Everything is working fine. The only problem is that it always begins with the first artist in the list. Is there any way that I can add a Javascript code onto this page that will return the results randomly?

    The software I'm using is called Article Manager (by InteractiveTools). Their forum suggested that Javascript might be able to be used to do what I'm wishing to do here.

    Any ideas? Many tia...

  • #2
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    See if this works. Insert after the <BODY> tag in the page that you want to redirect from.

    PHP Code:
    <script language="javascript">
    var 
    totalPages 16;
    var 
    randomPage = (Math.round((Math.random()*totalPages)+1));
    location.href 'http://www.artcorporation.org/cgi-bin/artman/exec/search.cgi?template=search%2Fsinglearticleresults-default.html&perpage=1&cat=1&search=1&start='+randomPage;
    </script> 
    Last edited by theekid182; 01-07-2005 at 07:36 AM.

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thx, theekid182. I gave it a try, but what it seems to be doing is opening the page over and over again, without downloading any of them fully. Just like a woman -- can't make up it's mind which one it wants to choose! j/k

    It seems to be opening the page over and over again is that after I paste the code in and hit the button for that area, I get a bouncing blank screen.

    When I hit the back button, I get a whole bunch of the same page on the drop-down menu for it. It seems to be cycling through all of them, not arriving at any of them to show on the screen, though. Thanks so much for the effort, though. You rock.

    Still interested in hearing if anyone else has another work-around for this. Much appreciate whatever help there might be out there...

    Have a good weekend,

  • #4
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ummm... Put the code in a new page that you want to use as your redirecting page.

  • #5
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this instead... Insert this script after the <BODY> tag like you did before.

    I changed the script to only go to a random page on the very first time per session that the user visits this URL: http://www.artcorporation.org/cgi-bi...art=1&search=1

    Let me know if this works for you.

    I would assume that you would have to add the script to this page:
    http://www.artcorporation.org/artists/adamany.shtml

    But, I'm not quite sure how you have everything set up.

    PHP Code:
    <script language="javascript">

    if (
    location.href=='http://www.artcorporation.org/cgi-bin/artman/exec/search.cgi?template=search%2Fsinglearticleresults-default.html&perpage=1&cat=1&start=1&search=1') {
    if (!
    getCookie("redirect")) 
    {
        var 
    totalPages 16;
        var 
    randomPage = (Math.round((Math.random()*totalPages)+1));
        
    location.href 'http://www.artcorporation.org/cgi-bin/artman/exec/search.cgi?template=search%2Fsinglearticleresults-default.html&perpage=1&cat=1&search=1&start='+randomPage;
        
    setCookie("redirect""done")
    }
    }

    function 
    getCookie(name)
    {
        var 
    dc document.cookie;
        var 
    prefix name "=";
        var 
    begin dc.indexOf("; " prefix);
        if (
    begin == -1)
        {
            
    begin dc.indexOf(prefix);
            if (
    begin != 0) return null;
        }
        else
        {
            
    begin += 2;
        }
        var 
    end document.cookie.indexOf(";"begin);
        if (
    end == -1)
        {
            
    end dc.length;
        }
        return 
    unescape(dc.substring(begin prefix.lengthend));
    }

    function 
    setCookie(namevalueexpirespathdomainsecure)
    {
        
    document.cookiename "=" escape(value) +
            ((
    expires) ? "; expires=" expires.toGMTString() : "") +
            ((
    path) ? "; path=" path "") +
            ((
    domain) ? "; domain=" domain "") +
            ((
    secure) ? "; secure" "");
    }

    </script> 
    Last edited by theekid182; 01-08-2005 at 09:41 PM.

  • #6
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thx so much! You've been really helpful on this.

    I tried the tweak, and it worked just as you said it would. I think I like what you've come up with here, and will test to see how it works out for us. We're conducting usability tests on the site the next couple of days, so I'll get some feedback on it.

    Thanks again for your generosity! You rock...

    Cheers,

  • #7
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by ilona
    Thx so much! You've been really helpful on this.

    I tried the tweak, and it worked just as you said it would. I think I like what you've come up with here, and will test to see how it works out for us. We're conducting usability tests on the site the next couple of days, so I'll get some feedback on it.

    Thanks again for your generosity! You rock...

    Cheers,
    Awesome!


  •  

    Posting Permissions

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