Run Javascript Once

Discussion in 'JavaScript' started by mark1, Aug 1, 2009.

  1. #1
    Ok. I did a search to find any easy solutions but I haven't found any.

    I am a n00b in javascript so please bear with me. I know what needs to be done though but I don't know how to do it.

    I want to run this script once only per day.
    <script src="example.js" language="javascript"></script>
    Code (markup):
    I know I have to use cookies... something along the lines of:
    http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_22775587.html
    http://www.weberdev.com/get_example-4280.html

    But I don't know how to implement this run once function. I don't know where to put the code in the html or what to put in the html and what to put in the separate javascript cookie file...

    Please help? Thanks!
     
    mark1, Aug 1, 2009 IP
  2. XDMCoder

    XDMCoder Peon

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    if(!isset($_COOKIE['coockieName']))
    {
    	$expire=time()+60*60*24;
    	setcookie("coockieName", "value", $expire);
    	echo "<script src=\"example.js\" language=\"javascript\"></script>";
    }
    ?>
    PHP:
     
    XDMCoder, Aug 2, 2009 IP
    mark1 likes this.
  3. mark1

    mark1 Peon

    Messages:
    372
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    XDMCoder you are a genious. Rep given for being SOOOO helpful!

    This is a much easier solution!
     
    mark1, Aug 2, 2009 IP
  4. XDMCoder

    XDMCoder Peon

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You'r welcome :D
     
    XDMCoder, Aug 2, 2009 IP