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 8919533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:03:17+00:00 2026-06-15T06:03:17+00:00

I have a script that redirects the user to a new page after X

  • 0

I have a script that redirects the user to a new page after X seconds. After being redirected, if the user hits their back button and returns to the page with this script I’d like it if the script does not fire again.

setTimeout(function() {
  window.location.href = "/mypage.html";
}, 3000);
  • 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-06-15T06:03:20+00:00Added an answer on June 15, 2026 at 6:03 am

    I used the link Cerbrus provided and went the cookie route to solve this. More complicated than I would have liked but it got the job done.

    This script will redirect the user to a new page after 3 seconds. It will first check if a cookie exists, and if it does it will not redirect. If there’s no cookie, it will create a cookie and then redirect the user. If the user hits the back button the script will find the cookie that was created and it will prevent the script from redirecting the user again.

    // Function to create a new cookie
    function createCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    
    // Function to read a cookie
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    
    // Use the readCookie function to assign the cookie to a variable (if it's available)
    var currentcookie = readCookie('mycookie');
    
    // If/else statement to fire javascript if the cookie is not present
    if (currentcookie) {
        // do nothing since the cookie exists
    }
    else {
        // Cookie doesn't exist, so lets do our redirect and create the cookie to prevent future redirects
    
        // Create a cookie
        createCookie('mycookie','true');
    
                // Perform the redirect after 3 seconds
        setTimeout(function() {
          window.location.href = "/mypage.html";
        }, 3000);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some script in my default page that redirects users to language specific
I have a script that uses a ton of redirects. About half way through
I have an if condition on a button which redirects to another page. I
I have a CustomeAuthorize action filter that forwards the user to signin page if
can I have a question about how to redirect the page after user invite
I have problems with redirecting user after authorization back to the app tab in
I have a form element that gets user details and a php script that
So I have a script (written in PHP) that posts the user input of
So I have a script (written in PHP) that posts the user input of
I have a bash script that includes the command: mv old.txt new.txt Old.txt doesn't

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.