• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Redirect to a specified URL

Redirect to a specified URL

Redirect to a specified URL

Use Window.location.href or Window.location.replace() to redirect to url. Pass a second argument to simulate a link click (true – default) or an HTTP redirect (false).

const redirect = (url, asLink = true) =>
  asLink ? (window.location.href = url) : window.location.replace(url);

// EXAMPLE
redirect('https://google.com');

Source

https://www.30secondsofcode.org/js/s/redirect

Miscellaneous

Related Snippets:

  • Make a resizable element
  • Determine whether two values are the same value
  • How to Get the Query String in JavaScript
  • Looping over an object’s keys and values

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2022 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us