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
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I change the content of a popup at night?

    Hi,

    I wonder if you can help. I am making a website and I would like to make the content of a popup change at a particular time of night.

    Basically the typical customer will have more 'purchase intent' in the evenings and we want to capitalise on that by giving a limited-time offer at a certain time in the day.

    How can I make this happen? I'm not sure what to google so can't really find anywhere where it has been done before or tutorials.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Code:
    var hourOfDay = ( new Date() ).getHours();
    if ( hourOfDay >= 18 || hourOfDay < 6 ) /* if time is between 6PM and 6AM */
    {
       ... show one popup ...
    } else {
       ... show another one ...
    }
    And it's kind of funny that you say you can't find the answer anywhere when almost identically this same question was asked and then answered just a few posts before yours in this same forum:
    Customized greeting based on time of the day
    Last edited by Old Pedant; 03-30-2013 at 11:56 PM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Do you mean your time of day or their time of day?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Logic Ali View Post
    Do you mean your time of day or their time of day?
    He says - "Basically the typical customer will have more 'purchase intent' in the evenings and we want to capitalise on that by giving a limited-time offer at a certain time in the day."

    So it must be the customer's time, which is very probably the same as his time as well.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So it was! Thanks for the answer oldpedant. And yes I'm in the uk, and so are the customers so we are only concerned about them.

    On that note, am I able to display a different webpage for people who visit from the US? That would be perfect!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Creatrixmarket View Post
    So it was! Thanks for the answer oldpedant. And yes I'm in the uk, and so are the customers so we are only concerned about them.

    On that note, am I able to display a different webpage for people who visit from the US? That would be perfect!
    That is somewhat contradictory!

    But yes, you can, provided the user (customer) has Javascript enabled in his browser:-

    Code:
    <script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
    
    <script type="text/javascript"> 
    
    var ccode =  geoip_country_code();   // 2-character country code, e.g. GB
    alert ("You are in " + ccode);  // for testing
    if (ccode == "GB") {
    // show info relating to GB
    }
    if (ccode == "US") {
    // show info relating to US
    }
    
    </script>
    Last edited by Philip M; 03-31-2013 at 06:13 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Creatrixmarket View Post
    On that note, am I able to display a different webpage for people who visit from the US? That would be perfect!
    Which was the reason for my original question. For reliability you need to use a go-ip service via a server side script. Using a JS interface to such a service makes the site dependent upon third-party scripts being enabled.


  •  

    Posting Permissions

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