How You Can Redirect to Another Web Url Using JavaScriptor JQuery?

To redirect page you can use javascript which is quite usefull to make this work window.location property to make a page redirect for this there is no need for jQuery.
If you do console.log(window.location)  you can see list of object return by browser.


//Retun by browser
Location {href: "", ancestorOrigins: DOMStringList, origin: "", protocol: "https:", host: "", …}
ancestorOrigins: DOMStringList {length: 0}
origin: ""
protocol: "https:"
host: ""
hostname: ""
port: ""
pathname: "/"
search: ""
hash: ""
href: ""
assign: ƒ assign()
reload: ƒ reload()
toString: ƒ toString()
replace: ƒ replace()
valueOf: ƒ valueOf()
Symbol(Symbol.toPrimitive): undefined
__proto__: Location

As you see if return serveral properties which you can use.But for redirect we will use window.location.replace(...) is better than using window.location.href, because replace() does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button process.

If you want to redirect by clicking/button on the link then use location.href

If you want to redirect HTTP auto then use location.href


For example:

// redirect auto HTTP

// redirect by clicking on the link/button
window.location.href = "";


Categories: Java Script Tags: #JavaScript,

Newsletter Subcribe

Receive updates and latest news direct from our team. Simply enter your email.