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:
- 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/');
- 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...');
- 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