Results 1 to 10 of 10

Thread: Sticky Note: With Cookie Write/Read Addition

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

    Default Sticky Note: With Cookie Write/Read Addition

    1) Script Title: Sticky note

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

    3) Describe problem:

    The script is great but I need it to write a cookie that lasts for 24 hours rather than per session-- I've tried to add this functionality but I have only succecced in breaking the script entirely. Help!
    Last edited by w0rdie; 02-28-2008 at 09:30 PM.

  2. #2
    Join Date
    Aug 2004
    Posts
    9,910
    Thanks
    3
    Thanked 969 Times in 957 Posts
    Blog Entries
    15

    Default

    Sure, try the below modified script in place of the original (script in the HEAD of your page):

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Sticky Note script-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * Visit DynamicDrive.com for hundreds of DHTML scripts
    * This notice must stay intact for legal use
    * Go to http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    //Specify display mode. 3 possible values are:
    //1) "always"- This makes the fade-in box load each time the page is displayed
    //2) "onceperday"- This uses cookies to display the fade-in box only once per 24 hr
    //3) integer (ie: 5)- Finally, you can specify an integer to display the box randomly via a frequency of 1/integer...
    // For example, 2 would display the box about (1/2) 50% of the time the page loads.
    
    var displaymode="onceperday"
    
    var enablefade="yes" //("yes" to enable fade in effect, "no" to disable)
    var autohidebox=["yes", 5] //Automatically hide box after x seconds? [yes/no, if_yes_hide_after_seconds]
    var showonscroll="yes" //Should box remain visible even when user scrolls page? ("yes"/"no)
    var IEfadelength=1 //fade in duration for IE, in seconds
    var Mozfadedegree=0.05 //fade in degree for NS6+ (number between 0 and 1. Recommended max: 0.2)
    
    ////////No need to edit beyond here///////////
    
    if (parseInt(displaymode)!=NaN)
    var random_num=Math.floor(Math.random()*displaymode)
    
    function displayfadeinbox(){
    var ie=document.all && !window.opera
    var dom=document.getElementById
    iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
    objref=(dom)? document.getElementById("fadeinbox") : document.all.fadeinbox
    var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
    var docwidth=(ie)? iebody.clientWidth : window.innerWidth
    docheight=(ie)? iebody.clientHeight: window.innerHeight
    var objwidth=objref.offsetWidth
    objheight=objref.offsetHeight
    objref.style.left=docwidth/2-objwidth/2+"px"
    objref.style.top=scroll_top+docheight/2-objheight/2+"px"
    
    if (showonscroll=="yes")
    showonscrollvar=setInterval("staticfadebox()", 50)
    
    if (enablefade=="yes" && objref.filters){
    objref.filters[0].duration=IEfadelength
    objref.filters[0].Apply()
    objref.filters[0].Play()
    }
    objref.style.visibility="visible"
    if (objref.style.MozOpacity){
    if (enablefade=="yes")
    mozfadevar=setInterval("mozfadefx()", 90)
    else{
    objref.style.MozOpacity=1
    controlledhidebox()
    }
    }
    else
    controlledhidebox()
    }
    
    function mozfadefx(){
    if (parseFloat(objref.style.MozOpacity)<1)
    objref.style.MozOpacity=parseFloat(objref.style.MozOpacity)+Mozfadedegree
    else{
    clearInterval(mozfadevar)
    controlledhidebox()
    }
    }
    
    function staticfadebox(){
    var ie=document.all && !window.opera
    var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset
    objref.style.top=scroll_top+docheight/2-objheight/2+"px"
    }
    
    function hidefadebox(){
    objref.style.visibility="hidden"
    if (typeof showonscrollvar!="undefined")
    clearInterval(showonscrollvar)
    }
    
    function controlledhidebox(){
    if (autohidebox[0]=="yes"){
    var delayvar=(enablefade=="yes" && objref.filters)? (autohidebox[1]+objref.filters[0].duration)*1000 : autohidebox[1]*1000
    setTimeout("hidefadebox()", delayvar)
    }
    }
    
    function initfunction(){
    setTimeout("displayfadeinbox()", 100)
    }
    
    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = ""
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset)
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    
    if (displaymode=="onceperday" && get_cookie("fadedin")=="" || displaymode=="always" || parseInt(displaymode)!=NaN && random_num==0){
    if (window.addEventListener)
    window.addEventListener("load", initfunction, false)
    else if (window.attachEvent)
    window.attachEvent("onload", initfunction)
    else if (document.getElementById)
    window.onload=initfunction
    if (displaymode=="onceperday"){
    var expireDate = new Date()
    var expstring=expireDate.setDate(expireDate.getDate()+1) //1 day to expire
    document.cookie="fadedin=yes; expires="+expireDate.toGMTString()
    }
    }
    
    
    </script>
    Not extensively tested though, but seems to behave correctly in terms of the 24hr time limit.

  3. #3
    Join Date
    Feb 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much!

    Everything works except that the cookie seems to still be based on the browser session in IE 6 and 7.

  4. #4
    Join Date
    Aug 2004
    Posts
    9,910
    Thanks
    3
    Thanked 969 Times in 957 Posts
    Blog Entries
    15

    Default

    Are you sure? The code above was tested in IE7, and the cookie does persist beyond just the browser session for me.

  5. #5
    Join Date
    Feb 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It does infact work! Thank you SO much.

  6. #6
    Join Date
    Sep 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This modification looks awesome and handly. I dont know anything about cookies but I'm wondering if it would be possible to add a "Do Not Show This Sticky Note Ever Again" option to not invade the users experiences if they grow irritated of it. Please, could somebody suggest how I would go about this?

  7. #7
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,025
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    That would be a great addition - perfect for one of those 'read our privacy policy and accept cookies' reminders too. Good idea Jessic4
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    geez... I'm glad I don't live in the UK. I can't imagine how much of a PITA it is to deal with that stupid cookie law

  9. #9
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,025
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    Yes, it is very tiresome

    The plus side is that its a convenient reminder to crack open the hob nobs!
    (I've learnt my lesson > http://www.mcvities.co.uk/product/hobnobs )
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,133
    Thanks
    44
    Thanked 3,229 Times in 3,190 Posts
    Blog Entries
    12

    Default

    I've updated the script to do that. See:

    http://www.dynamicdrive.com/forums/s...266#post282266
    - John
    ________________________

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

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
  •