In my last article I discussed the Dom Location Object Properties. Here, we will go over the Methods of those same objects, and if there is time, I will even cover the History Objects, which give you control over the user’s history list, allowing you to give them access to past URLs and advanced navigation.
Methods of the DOM Location Object - Assign() Gives You Tasks (Page 2 of 4 )
The assign() method does what the table in the previous section says: it allows you to load a new document or page. The proper syntax is location.assign(the URL to load). Its usage ranges from the simple to the complex. Here, in our first example, we will create a page that relocates a user to a different page:
Once the page loads, it triggers the script and loads a new page -- in this case, www.developershed.com.
You may not wish to automatically send your user to another page. Perhaps you want to give them an option to load the page. Below is a sample that acts like a hyperlink, but takes a lot longer to code:
<input type="button" onclick="loadnewURL()" value="Go To Another Site">
</body>
</html>
The above code will display two buttons. When you click the button that says “Display Present URL” it triggers a function that will display a pop-up alert containing the URL of the present address. If you click the button labeled “Go To Another Site,” it will trigger the loadnewURL function, which in this case loads the site www.aspfree.com