Results 1 to 7 of 7

Thread: Style Sheet Switcher (v1.1) - random style on every new site visit

  1. #1
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Style Sheet Switcher (v1.1) - random style on every new site visit

    1) Script Title: Style Sheet Switcher (v1.1)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...etswitcher.htm

    3) Describe problem: This is the best styleswitching script I have come across and does almost everything you need but I was wandering, would it be possible to update the script to select a random css file on every new visit to the site?
    What I am thinking of is very similar to the new browser session functionality which it currently has but what I was hoping was if the user browses away from the site and then back again (without closing the browser window) a new random css is called.
    I'm not even sure if this is possible with javascript but would love it to be.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Unless I read the script wrong, it looks like it can already do that. Here:

    Code:
    //Style Sheet Switcher version 1.1 Oct 10th, 2006
    //Author: Dynamic Drive: http://www.dynamicdrive.com
    //Usage terms: http://www.dynamicdrive.com/notice.htm
    
    var manual_or_random="manual" //"manual" or "random"
    var randomsetting="3 days" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
    
    //////No need to edit beyond here//////////////
    
    function getCookie(Name) { 
    var re=new RegExp(Na . . .
    Set it like:

    Code:
    var manual_or_random="random" //"manual" or "random"
    var randomsetting="eachtime" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    matteus (07-03-2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    No, I wish it did but I've looked into all those functions.
    All 'eachtime' does is change the style sheet every time a page is entered so the stylesheet is different everytime you click an internal link on the site.

    What I need it to do is stay the same for the whole visit (ie as long as the user is browsing around the site), then if they navigate away from the site and back again it changes.

    I'm currently using 'sessiononly' which is nearly what I want but requires you to close the browser and then re-open before the style sheet changes.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    I don't think there is any reliable way to get the type of information you would need to do that.

    In today's modern browsers it's tricky to even know where someone is in relation to your site because they may have more than one tab of it open, even with older non-tabbed browsers, they may have more than one window of it open. But basically what you are asking for is a way of knowing if the user has come to the page from within or from without of the site, that can be told sometimes via the document.referrer property, which will (if a link was used to get to your page) usually contain the URL of the page the user came from. But if someone just pastes the address in, or uses a bookmark to get to your page, or uses the back and forward buttons to navigate, that property will be empty, and there will be no way of knowing if they came from within or without.

    Another idea I had was that we could have all links that leave your site delete the cookie. That would require a script that would initialize the links on every page, similar to an 'open off site links in a new window' script, only instead of opening a new window, it would delete the cookie. But users could open their own new window when they hit one of those links, so not really be leaving your site, or you may already be opening some or all off site links in a new window. And they could always leave your site without clicking on any link on it by using bookmarks or what have you, as mentioned before.

    Before I started writing all of this, I thought, "I don't think there is any way to really know that". The more I think about it, the more I think I was right in the first place. I hope my above ruminations help you to see why though.

    Then again, I may still be missing the point, as I obviously did at first with this. If you (or anyone really) can think of some measurable by javascript event that would demark when you want to change the style and when not, then we could go with that.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks again jscheuer1. It's always good to discuss these things and you raised some very valid and interesting points which have opened my eyes to the potential enormity of what I'm asking.

    I'm a relative beginner with Javascript but am starting a bit of a frontend trial by fire and I think the sessiononly option does cover what I need for a job I'm doing at the moment.

    This is one of those things that I'm sure can be done in, like you said, a measurable way. If I have a eureka moment I'll post it up!

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,997
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    If you have PHP or another server side language available to you on your host, I believe there is or can be made to be a session variable that can track when a user is on the site, but I believe all of your pages would have to be server pages, and that even then, due to the complex nature of the way folks surf (or perhaps only if the tracking code were not well thought out), there could be slip ups, but much less likely than with all of the methods I was thinking about before.

    However, I'm not 100% sure if this can be really effective without requiring a login. Anonymous users could be tracked by their IP address, but obviously others could have the same IP. I'm not real up on server side stuff though, so there may be a better way to track anons.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    You are right there. Php does have the capability of making a session variable available throughout the site. I use php on a day to day basis and I think it could be used to interact with this javascript as a kind of widget on every page.
    I was hoping to do it with javascript alone thus making it much more robust and transferrable to any other project seamlessly.
    Thanks for your attention to this topic though.

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
  •