Best way to redirect to another webpage in JavaScript.
Image Source: Picsum

If you want to redirect to another webpage in JavaScript, you can use the following methods:

Method 1: Redirect to Another Webpage Using window.location

window.location = "https://www.example.com";

Method 2: Redirect to Another Webpage Using window.location.href

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

Method 3: Redirect to Another Webpage Using window.location.replace

window.location.replace("https://www.example.com");

Method 4: Redirect to Another Webpage Using window.location.assign

window.location.assign("https://www.example.com");

Method 5: Redirect to Another Webpage Using window.location.replace

window.location.replace("https://www.example.com");
The SQL Whisperer

The SQL Whisperer

Senior Backend Engineer with a deep passion for Ruby on Rails, high-concurrency systems, and database optimization.

Using preload and prefetch in HTML
Prev post

Using preload and prefetch in HTML

Next post

10 Best Social Media Optimization Tips For Your Brand Awareness

10 Best Social Media Optimization Tips For Your Brand Awareness