Home arrow JavaScript arrow Page 2 - Methods of the DOM Location Object
JAVASCRIPT

Methods of the DOM Location Object


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.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
December 08, 2008
TABLE OF CONTENTS:
  1. · Methods of the DOM Location Object
  2. · Assign() Gives You Tasks
  3. · The Jatrix…Reloaded()
  4. · Replace()

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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



blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials