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:
<html>
<head>
<script type="text/javascript">
window.location.assign(http://www.developershed.com);
</script>
</head>
<body>
</body>
</html>
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:
<html>
<head>
<script type="text/javascript">
function presentUrl()
{
alert(window.location);
}
function loadnewURL()
{
window.location="http://www.aspfree.com";
}
</script>
</head>
<body>
<input type="button" onclick="presentURL()" value="Display Present URL">
<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

Next: The Jatrix…Reloaded() >>
More JavaScript Articles
More By James Payne