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

  • Home
  • SEARCH
  • 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 6046977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:18:03+00:00 2026-05-23T07:18:03+00:00

I have come up with the following code, which allows users to view a

  • 0

I have come up with the following code, which allows users to view a page with a movie embed for 30 seconds before redirecting them away from the page. Additionally, they can click a link to hide the div with this countdown. What I need help with is canceling the redirect (stopping it from happening) if that link is clicked, so users can continue to watch the full movie. Thanks in advance for your help!

Javascript:

<script type="text/javascript">
var settimmer = 0;
    $(function(){
            window.setInterval(function() {
                var timeCounter = $("b[id=show-time]").html();
                var updateTime = eval(timeCounter)- eval(1);
                $("b[id=show-time]").html(updateTime);


                if(updateTime == 0){
                    window.location = ("redirect.php");
                }
            }, 1000);

    });
</script>

<script type="text/javascript">

    $(document).ready(function(){

    $(".slidingDiv").show();
    $(".show_hide").show();

$('.show_hide').click(function(){
$(".slidingDiv").slideToggle();
});

});
</script>

HTML:

<div id="my-timer" class="slidingDiv">
    You have <b id="show-time">30</b> seconds to decide on this movie.
<a href="#" class="show_hide">Yes, I want to watch this one!</a>
</div>
  • 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-23T07:18:04+00:00Added an answer on May 23, 2026 at 7:18 am

    setInterval returns a value you can use to cancel the interval timer via clearInterval. So:

    $(function(){
            //  +--- Remember the value from `setInterval
            //  |
            //  v
            var timerHandle = window.setInterval(function() {
                var timeCounter = $("b[id=show-time]").html();
                var updateTime = eval(timeCounter)- eval(1);
                $("b[id=show-time]").html(updateTime);
    
    
                if(updateTime == 0){
                    window.location = ("redirect.php");
                }
            }, 1000);
    
            // + Hook up a handler for the link that uses the handle to clear it
            // |
            // v
            $("selector_for_the_link").click(function() {
                clearInterval(timerHandle);
                timerHandle = 0;
            });
    });
    

    Note that I’ve put the variable inside your ready function, so it isn’t a global.


    Off-topic: You don’t need or want to use eval in the above (in fact, you virtually never want to use eval at all, for anything). If you want to parse a string to make a number, use parseInt (and there’s never any reason to eval a literal like 1). So this line:

    var updateTime = eval(timeCounter)- eval(1);
    

    becomes

    var updateTime = parseInt(timeCounter, 10) - 1;
    

    (The 10 means the string is in decimal — e.g., base 10.)

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

Sidebar

Related Questions

I have come across the following type of code many a times, and I
I am a newbie to Python and have come across the following example in
When writing GUIs, I've frequently come over the following problem: Assume you have a
I have come across a lot of optimization tips which say that you should
(ASP.NET Web Application) I'd like to create a page which allows the user to
I'm new to Java and I have come to having the following problem: I
Just wondering if someone can assist me with the following issue. I have come
I have the following code: private SetMultimap<String, Dynamic> dynamicFields = TreeMultimap.create(Ordering.natural(), new Comparator<Dynamic>() {
I have the following in my XSL which adds a xmlns to my XML.
I have a login.jsp page which contains a login form. Once logged in the

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.