Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6531315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:51:47+00:00 2026-05-25T09:51:47+00:00

I have a jquery plugin that autofreshes the page every 5 mins. (function($) {

  • 0

I have a jquery plugin that autofreshes the page every 5 mins.

(function($) {
  $.fn.refreshPage = function() {

    setInterval(function() {
      function x();
    }, 300);
  };
})(jQuery);

but the problem is that I want it to reset the timer when a certain function runs, I’ve read about clearInterval, but I’m not sure how to implement that here. To be more specific, I want function x to clear the interval everytime it runs.

Follow up question:

How do I call clearInterval on a function on another file given the current structure of my plugin? Sorry noob here. Thanks!

Any help would be appreciated. Thanks in advance!

UPDATE:

My plugin now looks like this

(function($) {
  var refresh_timer;
  $.fn.refreshPage = function() {

    refresh_timer = setInterval(function() {
      function x();
    }, 300);
  };
  $.fn.reFreshPage.resetTimer = function() {
    clearInterval(refresh_timer);
})(jQuery);

And I call:

$.fn.reFreshPage.resetTimer

to reset the intervals, but the problem is that it breaks the setInterval and no longer refreshes the page after the timer has been reset. Am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:51:47+00:00Added an answer on May 25, 2026 at 9:51 am

    You just have to remember the return value from the original call to setInterval and you can then pass that to clearInterval in order to stop the timer.

    var timer = setInterval(...);
    clearInterval(timer);
    

    Sometimes, when you want more control, it’s easier to not use setInterval(), but to use setTimeout() and just repeatedly call setTimeout() on each successive timer until you want it to stop. This technique also makes it easier to vary the timer interval if desired.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function called Colorbox (jQuery plugin) that takes a number of parameters
Using the jquery metadata plugin, I have an element on my page that looks
I have this jquery plugin that zooms in on photos, but I would like
I have a jQuery plugin that I am using: $(document).ready(function(){ $('.elements').fancyPlugin(); }); This works
I have a small jQuery plugin that I use for form AJAX validation. There
does jquery have any plugin that prevents entering any input to a textbox that
I have been trying to make this to be a little jQuery plugin that
Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said
I have a modal dialog plugin written in jquery, that binds to the click
I have the jQuery numberformatter-plugin installed, but don´t get it to work correctly. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.