Cotton Rohrscheib

The Cotton Club Blog & Podcast

  • Home
  • Bio
    • Resume
  • Blog
    • Faith & Family
    • Marketing & Tech
    • Farm & Business
    • Entertainment
    • Health & Wellness
    • Urban Farming
    • Weekend Projects
  • Media
    • Newsletter
    • Photo Galleries
    • Instagram Feed
    • Video Archives
    • Podcasts
    • Music Playlists
  • Books
  • Connect
    • Rohrscheib Capital
    • Disclaimer
    • Privacy Policy
You are here: Home / Marketing & Tech / Redirecting a Browser w/ Javascript

Redirecting a Browser w/ Javascript

January 30, 2009 by Cotton Rohrscheib 1 Comment

I had someone DM me this morning on Twitter and ask me what I recommended for them to use to redirect a browser using Javascript. 

My gut reaction was to tell them not to do it with JavaScript, but to use Apache Redirection instead, but I went ahead and shared w/ them three ways I know to do this.

I am sure that there are more ways in javascripting to do this same thing that I don’t know about but these snippets have been in my tool box for years and they work:

Script #1 – Stealth Redirect

This allows you to redirect a page without telling your visitor, they probably won’t even notice it happen.

   1: <html>
   2: <script>
   3:     location = "http://cottonrohrscheib.com";
   4: </script>
   5: </html>

Script #2 – Alert Redirect

If you want visitors to know that the page has been moved you could use this script. It uses a JavaScript alert, to tell your visitor that the page has been moved, then when they click OK, their browser is redirected.

   1: <html>
   2: <script>
   3:     alert("This page has been moved to a new location... click OK to be redirected?");
   4:     location = "http://www.cottonrohrscheib.com";
   5: </script>
   6: </html>

Script #3 – Confirm Redirect

If you want to give your visitors more control, you can use a confirm dialog. This script gives visitors the option to either be redirected to the new location or go back to the previous page.

   1: <html>
   2: <script>
   3:     if(confirm("This page has been moved to a new location... would you like to be redirected?"))
   4:     {
   5:         location = "http://www.cottonrohrscheib.com";
   6:     }
   7:     else
   8:     {
   9:         history.back();
  10:     }
  11: </script>
  12: </html>

As I mentioned, these all work, just pick out which one best suits your particular situation.  Be sure to change out the URL from mine to yours and you should be good to go.

Share this post on:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest

Related

About Cotton Rohrscheib

The Cotton Club is a monthly podcast hosted by me, Cotton Rohrscheib. I'm a 52 year old entrepreneur w/ ADHD, OCD (and now AARP) that refuses to grow up as I grow old. I have collaborated and invested in hundreds of projects throughout my career in multiple industries such as; technology, healthcare, and agriculture. I also have 25 years experience in the marketing industry as a co-founder of an award-winning advertising agency. I will undoubtedly cover a wide variety of topics on my podcast while sharing some really crazy stories and situations that I've been fortunate to witness firsthand. I also have a book coming out in 2025 titled, "Mistakes were Made"

Please Drop Your Questions or CommentsCancel reply

Let’s Connect

  • Email
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter

Recent Updates

  • EP:032 – Cotton Rohrscheib & Diana DeHart
  • Challenges & Opportunities Going into 2025
  • Find us at the 2025 Arkansas Women in Agriculture Conference in Hot Springs, Arkansas
  • Be Sure to Checkout FBN’s Farmers First™  Crop Nutrition & Adjuvant Lineup for 2025
  • What we all need in Dark Times…

Blog Categories

  • Blog (419)
  • Entertainment (376)
  • Faith & Family (147)
  • Farm & Business (288)
  • Health & Wellness (33)
  • Marketing & Tech (584)
  • Podcasts (31)
  • Urban Farming (20)
  • Weekend Projects (1)

Listen & Subscribe

Blog Archives

Join the Cotton Club!

 

Content Copyright: 2001-2025
Cotton Rohrscheib | Rohrscheib Capital