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.
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by Philip M View Post
    Only a tiny minority of people disable Javascript in their browser
    that may or may not be true, but in either case if something can be done both client and server side, I will always do it server side first so I don't have to have a plan B for javascript disabled browsers and then do it client side as an optional "extra" if required.

    If you want to determine if something has already been done, prior to loading the page in the browser, on a given day you don't need javascript or cookies. You can do it server side.

    I don't see any point in wasting time with javascript if I can do exactly the same thing server side.
    Last edited by bullant; 06-19-2011 at 10:06 AM.

  2. #17
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    My position is that these days Javascript is absolutely essential for web participation. Most sites rely on Javascript for functionality, not just decoration. Everyone knows that (all) Javascripts will not work if Javascript is disabled in the browser. They will not work if the computer is not connected to a power source either. The point you make is valid, but utterly trivial.

    Many banking (and other) sites point out that you must have Javascript and cookies enabled if you are to be able to use them.

    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.

  3. #18
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by Philip M View Post
    My position is that these days Javascript is absolutely essential for web participation.
    I agree if the functionality cannot be done server side

    If it can be done server side then I will always do it server side first and then do it client side as well as an optional "extra" if it is required.

    Like I said, personally I don't see any point in wasting time doing something client side if the same functionality can be done server side

  4. #19
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    To set a cookie which will expire in one hour:-

    Code:
    <script type = "text/javascript">
    
    function createCookie(name, value){
    var today = new Date;
    today.setTime(today.getTime()+ 3600000);  // = 1 hour
    document.cookie = name + "=" + value + "; expires=" + today.toGMTString();
    alert (name + " value is: "+ value + "\nExpires in: " + today);
    }
    
    createCookie("myName", "myValue");
    
    </script>
    Then start by reading the cookie - if it is found do this, if it is not found do that.

    Code:
    <script type="text/javascript">
    function createCookie(name,value,days) {
    if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    }
    Thank you for your quick answer , as i have stated iam inexperienced and found that by just altering your previous code replacing 24 with 1 in
    Code:
    date.setTime(date.getTime()+(days*1*60*60*1000));
    does the job for me by creating a cookie with 1 hour validity , it was much more effort for me to use the new script you provided than alter the previous one. in any case thank you and appreciate your help.

    @bullant yes i think server side is always better cause you have total control but already as philip said my site relies heavily on jscript so its not an option for me. thank you for your suggestion.

    john

  5. #20
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by kegra View Post
    @bullant yes i think server side is always better cause you have total control but already as philip said my site relies heavily on jscript so its not an option for me. thank you for your suggestion.
    No problem . Was just making sure you were aware of other possible options.

  6. #21
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bullant View Post
    No problem . Was just making sure you were aware of other possible options.
    also to make fun of the situation (how much i rely on jscript) i am using ccs3 transformations that work flawlesly on webkit browsers except IE
    eg i use rotate and skew on html elements but for this to work i have a jscript (the excellent work of Zoltan sand transformations) that transforms the transformations LOL into IE understandable format....

  7. #22
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by kegra View Post
    also to make fun of the situation (how much i rely on jscript) i am using ccs3 transformations that work flawlesly on webkit browsers except IE
    Since css3 is not yet officially released and support for it varies in browsers, I'm not touching it for commercial work yet.

  8. #23
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [QUOTE=Philip M;993154]You need to set a cookie. Many examples have been posted in this forum - here is one of them. You set the expiry date to the desired number of days ahead (here 365 days - change yours to 1 or whatever).

    Code:
    <html>
    <head>
    <title>Welcome Message Displays Once Only</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <script type="text/javascript">
    function createCookie(name,value,days) {
    if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }
    
    function eraseCookie(name) {
    createCookie(name,"",-1);
    }
    
    </script>
    
    </head>
    <body>
    <script type="text/javascript">
    if(!readCookie('visitedPreviously')){
    document.write(' Your Message Goes Here And You See It Only Once ');
    createCookie('visitedPreviously', 'visitedPreviously', 365);  // 365 days persistence
    }
    
    //eraseCookie('visitedPreviously');  // FOR TEST PURPOSES
    
    </script>
    </body>
    </html>
    Note that "a day" means 24 hours, not exactly the same thing as the next day starting at midnight.

    Thanks Phillip M. This is great! (#2 response)
    However, is it possible to make the message appear in an alert box rather than just on the page itself? I'm guessing that 'document.write' puts it on the page. Is there something that will create an alert box instead?
    jmatuska

  9. #24
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    [QUOTE=jmatuska;1278167Thanks Phillip M. This is great! (#2 response)
    However, is it possible to make the message appear in an alert box rather than just on the page itself? I'm guessing that 'document.write' puts it on the page. Is there something that will create an alert box instead?
    jmatuska[/QUOTE]

    Well, alert boxes are not considered a very professional way of displaying information to a user.

    But if you replace document.write by alert then you ought to get an alert.

    But naturally you could display the message in a <span> styled in whatever fancy way you wish.
    Last edited by Philip M; 10-10-2012 at 08:20 AM.

    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.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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