Cotton Rohrscheib

The Cotton Club Blog & Podcast

  • Home
  • About
    • Entrepreneurial Journey
  • Blog
    • Faith & Family
    • Marketing & Tech
    • Farm & Business
    • Entertainment
    • Health & Wellness
    • Urban Farming
    • Weekend Projects
  • Podcast
  • Newsletter
  • Media
    • Photo Galleries
    • Video Archives
  • Marketplace
    • Buying Gold & Silver
    • Accoutrements
      • Bags & Briefcases
      • Notebooks
      • Personal Carry
      • Wallets
    • Artwork
    • Banknotes & Currency
      • Currency
      • Gold Banknotes
      • Silver Certificates
    • Sports Memorabilia
    • CIvil War Relics
    • Native American Artifacts
      • Individual Pieces
      • Groups (Cache)
    • Pens
    • Rare Books
    • Rare Coins
      • Coin Sets
      • Individual Coins
    • Signs & Advertising
    • Stock Certificates
    • Trading Cards
      • Trading Cards: Autographs
      • Trading Cards: Base
      • Trading Cards: Graded
      • Trading Cards: Raw
      • Trading Cards: Pokémon
      • Trading Cards: Sets
    • Vintage Toys
      • Buddy L
      • Ertl Farm Toys
      • GI Joe
      • Masters of the Universe
      • Hot Wheels
      • Lionel Trains
      • Lunch Boxes
      • Marx Toys
      • NASCAR Die-Cast
      • Schleich Toys
      • Star Wars
      • Tonka Trucks
      • Walt Disney Productions
    • Vintage T-Shirts
    • Vinyl Records
    • Watches & Jewelry
  • Connect
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:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Email a link to a friend (Opens in new window) Email
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Pinterest (Opens in new window) Pinterest

Filed Under: Marketing & Tech Tagged With: .htaccess, JavaScript

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"

Leave a Reply Cancel reply

You must be logged in to post a comment.

  • Email
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter

Recent Updates

  • Collection of Native American Artifacts
  • Coming Soon: High Cotton Trading Cards Booster Boxes & Hanger Packs
  • The Marketplace is now Connected to eBay!
  • Ep034: Cotton Rohrscheib & Tim Volberding
  • I Stay on Track w/ Reminders & Task Lists

Blog Categories

  • Blog (442)
  • Entertainment (378)
  • Faith & Family (155)
  • Farm & Business (304)
  • Health & Wellness (38)
  • Marketing & Tech (593)
  • Podcasts (33)
  • Urban Farming (24)
  • Weekend Projects (12)

Blog Archives

Join the Cotton Club!

 

Content Copyright © 2000-2026
Cotton Rohrscheib | Rohrscheib Capital
Disclaimer | Privacy Policy | Account Manager | View Cart

All opinions expressed on this website are 100% Cotton (see my disclaimer). All content, including text, images, and media, are the intellectual property of Rohrscheib Capital unless otherwise noted. To learn how we use your private information, checkout our privacy policy.