How do I redirect to another webpage in javascript or jQuery?
Navigate to a new page in javascript:
Example 1:
location = "http://studentboxoffice.in";
Note: Though Window.location
is a read-only Location object, you can also assign a DOMString
to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com'
is a synonym of location.href = 'http://www.example.com'
.
Example 2:
location.assign("http://studentboxoffice.in");
Example 3:
location.replace("http://studentboxoffice.in");
How the assign() and replace() differs
The difference between replace()
and assign()
method, is that replace()
removes the URL of the current document from the document history, means it is not possible to use the "back" button to navigate back to the original web page. So Use the assign()
method if you want to load a new document, and want to give the option to navigate back to the original web page.
Navigate to a new page in jQuery:
let url = "http://studentboxoffice.in";
$(location).attr('href', url);
-
CreatedJan 17, 2020
-
UpdatedNov 03, 2020
-
Views1,443