A redirection is when a HTTP request for one page is automatically sent to another page. There are many reasons you might want to redirect users to other pages. For example, perhaps your site has changed to a new domain and you need to redirect your users to the new URL, or perhaps an old page has since been updated and you need to send users to the most recent version. Other reasons you might want to use redirects include redirecting from HTTP to HTTPS, sending a user to a different page based on their language or location, or sending them to the next page of a form. Here’s how to use JavaScript to redirect users to other pages.

Using JavaScript To Redirect to A New Page

If you’ve changed to a new domain name and wish to send your users to the new site, JavaScript can help through the use of a 301 redirect. This is basically when the server makes use of a 301 status code to let the user agent know that a new address exists. This is one of the easiest ways to redirect users using JavaScript, and you can make use of either of the following snippets of code:

window.location.assign(“new URL”); or window.location.replace(“new URL”);

The “location.replace” snippet is one of the simplest ways to redirect users to new URLs using JavaScript. You can also make use of “window.location.href”.

Using JavaScript To Redirect A Page After A Set Amount of Time

Let’s say you want to perform a redirect to a different webpage, but not straight away. Instead, you want to give the user some time on your initial page or site and then transfer them to a different page after a set amount of time. To do this, the JavaScript code is actually very simple:


setTimeout(function() {

window.location.href = “https://www.yourwebsite.com”;

}, 5000);


In this code example, you’ll need to replace the https://www.yourwebsite.com with the URL of the webpage you’d like to redirect to. You’ll also see the number 5000 at the end of the code. This number can be adjusted and actually determines how long the user remains on the initial page before the redirect occurs. In this case, 5000 equates to 5 seconds (or 5,000 milliseconds).

Using JavaScript To Redirect A Page on Loading

You can actually use JavaScript to redirect a user to another website or webpage as soon as they open up your initial page. This is done by making use of the following code:


window.location.href = “https://www.yourwebsite.com”;


To use this code, it simply needs to be placed within the <head> element, replacing the https://www.yourwebsite.com with the URL of your chosen page or site, as mentioned previously. It’s important to note, however, that when using this code, the user will not see any of the initial webpage they clicked on.

Using JavaScript To Redirect A Page After an Action Is Completed

Perhaps you don’t want to redirect a user to a new page straight away, but wish to perform a redirection after a certain action or event takes place on the initial page. This could be anything from clicking on a certain button, submitted a form, downloading a file, and more. In these kinds of situations, you’ll need to make use of either a condition check or assign a certain action to the process for redirection.

Here’s an example of a condition check:


// Check if the condition is true and then redirect.

if ( … ) {

window.location.href = “https://www.example.com”;



In this case, if the condition is met, the redirect will occur.

Redirecting Users to Quality Webpages

When making use of JavaScript to redirect users to different URLs, it’s important to ensure that the content of those pages is sufficiently interesting and engaging in order to hold the reader’s attention. If you need help writing quality content for your website, contacting a highly rated writing services like SuperiorPapers is a smart first move. They’ll be able to offer full proofreading, editing, and custom writing services to create winning content for your webpages and redirects.


Redirects are sometimes essential, but always need to be used with care; redirecting users from one page to another without suitable justification will only frustrate them and encourage them to leave your site. It’s also worth noting that search engines don’t particularly like redirects, so if you want your site to be listed high up in search engine results, it’s vital to be careful and cautious when using redirects. As we’ve seen, however, there are several cases where redirects are essential, and by following these tips and tricks, you’ll be able to perform efficient redirects using JavaScript.

59 replies
  1. search
    search says:

    Hi there everyone, it’s my first go to see at this site, and article is in fact fruitful in support of
    me, keep up posting these types of articles or reviews.

  2. dnd languages
    dnd languages says:

    I am not sure the place you’re getting your info, however good topic.
    I must spend a while learning much more or figuring out more.

    Thank you for wonderful information I was searching
    for this information for my mission.

  3. Best London barbers
    Best London barbers says:

    Just want to say your article is as amazing. The clarity in your post is just
    spectacular and i can assume you’re an expert on this subject.
    Well with your permission let me to grab your RSS feed to keep updated
    with forthcoming post. Thanks a million and
    please keep up the enjoyable work.

  4. https://Jak-heifer.blogspot.com
    https://Jak-heifer.blogspot.com says:

    I blog quite often and I seriously appreciate your information. This great article has really peaked my interest.
    I’m going to book mark your website and keep checking for new
    details about once a week. I subscribed to your
    Feed as well.

  5. https://changwon-kropanma4.blogspot.com
    https://changwon-kropanma4.blogspot.com says:

    Very good blog you have here but I was wondering if you knew of any forums that cover the same topics talked about here?
    I’d really love to be a part of group where I can get comments from other experienced people that share
    the same interest. If you have any recommendations, please let me know.

  6. https://Earthquake-kropanma3.blogspot.com
    https://Earthquake-kropanma3.blogspot.com says:

    Howdy I am so thrilled I found your blog page, I really found you by mistake,
    while I was browsing on Bing for something else, Anyhow I am
    here now and would just like to say kudos for a incredible post and a all round thrilling blog (I also love the theme/design),
    I don’t have time to read it all at the moment but I have
    saved it and also included your RSS feeds, so when I
    have time I will be back to read more, Please do keep up the fantastic jo.

  7. https://youngdeok-massage.blogspot.com
    https://youngdeok-massage.blogspot.com says:

    You really make it seem so easy with your presentation however I to find this matter to be actually something which
    I feel I’d never understand. It kind of feels too complex and very broad for me.
    I am having a look forward to your next submit, I’ll attempt to get the cling of it!

  8. free swingers meeting
    free swingers meeting says:

    Greetings! This is my first visit to your blog!

    We are a collection of volunteers and starting a new project
    in a community in the same niche. Your blog provided us useful information to work on. You have
    done a marvellous job!

  9. http://myfolio.com/stephanieroper
    http://myfolio.com/stephanieroper says:

    Hello just wanted to give you a quick heads up. The words in your article seem to be
    running off the screen in Opera. I’m not sure if this is a format issue or something to
    do with web browser compatibility but I figured I’d post to let you know.
    The design and style look great though! Hope you get the issue resolved soon. Kudos

  10. club w88 download
    club w88 download says:

    Greetings I am so excited I found your blog page, I really found you by
    mistake, while I was researching on Yahoo for something else, Nonetheless I am here now
    and would just like to say cheers for a tremendous post and a all round
    interesting blog (I also love the theme/design), I don’t have time to look over it
    all at the moment but I have book-marked it and also included your RSS
    feeds, so when I have time I will be back to read
    more, Please do keep up the fantastic b.

  11. 우리카지노
    우리카지노 says:

    Hi there great website! Does running a blog like this take a massive amount work?
    I’ve no knowledge of programming however I was hoping to start my own blog soon. Anyhow,
    should you have any ideas or tips for new blog owners please
    share. I understand this is off topic nevertheless I simply needed to ask.

  12. thanks
    thanks says:

    Wow that was strange. I just wrote an very long comment but after I clicked submit
    my comment didn’t show up. Grrrr… well I’m not writing all
    that over again. Anyhow, just wanted to say superb blog!

  13. 온라인카지노
    온라인카지노 says:

    It’s the best time to make some plans for the future and
    it is time to be happy. I’ve read this post
    and if I could I want to suggest you few interesting
    things or advice. Perhaps you can write next articles referring to this article.

    I wish to read even more things about it!

  14. https://myspace.com/toptravel0
    https://myspace.com/toptravel0 says:

    Good day! I could have sworn I’ve been to this site before but after browsing through a few of the articles I realized it’s new
    to me. Nonetheless, I’m certainly happy I came across it and I’ll be book-marking it
    and checking back often!

  15. forex forum
    forex forum says:

    whoah this blog is fantastic i love reading your posts.

    Keep up the good work! You understand, many persons are
    looking round for this information, you could aid them greatly.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.