JavaScript Location assign() Tutorial

In this section, we will learn what the location assign() method is and how to use it in JavaScript.

JavaScript Location assign() Method

The `assign()` method is used to load a new webpage into the current browser window.

The method takes one argument and that is the name of the URL that we want to load.

Note: there’s no return value.

Location assign() Method Syntax:

location.assign(URL)

Location assign() Method Parameter:

The method takes one argument and that is the URL we want to load in the current browser window.

Location assign() Method Return Value:

There’s no return value from this method.

Example: using Location assign() method in JavaScript

See the Pen using Location search protocol in JavaScript by Omid Dehghan (@odchan1) on CodePen.

If we click the `Go to homepage` button, the document of the homepage will be loaded in the current browser window.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies