Jump to content


Photo

Disabling jquery on browser refresh...


  • Please log in to reply
4 replies to this topic

#1 notxalckram

notxalckram

    Forum Newcomer

  • Members
  • Pip
  • 28 posts

Posted 13 July 2017 - 11:59 AM

Is it possible to disable jquery code so the code does run again if the page is refreshed or visited again during the same user session?

 

What I'm trying to do is animate the introduction of content on my homepage and disable it from happening again if the user goes back to this page or refreshes it during their visit to my site. 

 

 



#2 NOCK

NOCK

    Chief Troll Hunter

  • Privileged
  • PipPipPipPipPip
  • 1,599 posts
  • Gender:Male
  • Location:Eastbourne, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 13 July 2017 - 02:04 PM

You could use localStorage and a check to see if something is set. If you put something like:

localStorage.set('animations-ran',true);

at the end of your JS and then use something like


if ( ! localStorage.get('animations-ran') ) {


    // your current JS code here


    localStorage.set('animations-ran',true);


}

Then your code should only run if the localStorage value is not true.

 

I've not tested the above but think it's fairly close, hope that helps?


Edited by NOCK, 13 July 2017 - 02:05 PM.


#3 rbrtsmith

rbrtsmith

    ReferenceError

  • Privileged
  • PipPipPipPipPip
  • 4,013 posts
  • Gender:Male
  • Location:Manchester, UK
  • Experience:Nothing
  • Area of Expertise:Web Developer

Posted 14 July 2017 - 07:23 AM

You could use localStorage and a check to see if something is set. If you put something like:

localStorage.set('animations-ran',true);

at the end of your JS and then use something like


if ( ! localStorage.get('animations-ran') ) {


    // your current JS code here


    localStorage.set('animations-ran',true);


}

Then your code should only run if the localStorage value is not true.

 

I've not tested the above but think it's fairly close, hope that helps?

Good idea, although it's worth considering using sessionStorage if you want the animation to re-run if the user were to close the window and revisit the site at a later date.  Local Storage will persist until the user either manually deletes it or your site overrides it.  Session storage will be removed when the users session expires (when they leave the site)


Edited by rbrtsmith, 14 July 2017 - 07:24 AM.


#4 NOCK

NOCK

    Chief Troll Hunter

  • Privileged
  • PipPipPipPipPip
  • 1,599 posts
  • Gender:Male
  • Location:Eastbourne, East Sussex
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 14 July 2017 - 11:27 AM

Good idea, although it's worth considering using sessionStorage if you want the animation to re-run if the user were to close the window and revisit the site at a later date.  Local Storage will persist until the user either manually deletes it or your site overrides it.  Session storage will be removed when the users session expires (when they leave the site)

 

Very good point, I didn't think about that.

 

OP, do what Robert said... replace my localStorage bits with sessionStorage :)



#5 notxalckram

notxalckram

    Forum Newcomer

  • Members
  • Pip
  • 28 posts

Posted 17 July 2017 - 07:39 AM

Hey guys, thanks for the help. I'll try this method out and get back to you =)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users