How to use JavaScript Location assign

In this article I have described about Dom Node compareDocumentPosition() method in JavaScript
  • 2664

JavaScript Location assign() method

  • As we know that location object contains information about the current URL.
  • The location object has a method named assign() method that load new document.

Browser support

Following are the main browsers which support the assign() method of location object

  • Internet Explorer.
  • Firefox.
  • Opera.
  • Google Chrome.
  • Safari.

Syntax

The assign() method of location object has following syntax

location.assign(urlname)

Lets take an example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">

    function document()

    {

        window.location.assign("https://dotnetheaven.com/category/javascript")

    }

</script>

</head>

<body style ="background-color:green">

<input type="button" value="Load Homepage" onclick="document()" />

</body>

</html>

OUTPUT

assign1.jpg

When we click on button it load The document as we give in url as a parameter in method name.

Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.