JavaScript location assign() method

The JavaScript location assign() method is used to load a new document in the current window or frame. It takes a single argument: the URL of the document to be loaded. It does not return a value.

Here are some examples of how the assign() method can be used in JavaScript code:

  1. To load a new document in the current window or frame, you can use the following code:
// load a new document in the current window or frame
location.assign('http://www.example.com/');
  1. To load a new document in the current window or frame with a custom message, you can use the following code:
// load a new document in the current window or frame with a custom message
location.assign('http://www.example.com/', 'Loading new document...');
  1. To load a new document in the current window or frame and execute a callback function, you can use the following code:
// define a callback function
function onLoadDocument() {
  // do something...
}

// load a new document in the current window or frame and execute the callback function
location.assign('http://www.example.com/', onLoadDocument);

Overall, the assign() method provides a convenient way to load a new document in the current window or frame. It can be useful for tasks such as implementing a link or button that redirects to a new page, or for other operations that require loading a new document in the current window or frame.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: