The window.location.assign()
method belongs to the Location
object. It allows the window to load a document specified by the provided
location.assign(url)
// OR
window.location.assign(url)
url
: this is the
Let’s use the window.location.assign()
to navigate to "https://educative.io/answers"
.
In the example below, we create a navigate()
function that will call the window.locaton.assign()
.
An onclick
event listener is added to the button to call this function when it is clicked.
Note: An incorrect URL will throw a
DOMException
error.
"hps://educative.io/edpresso"
.