Home arrow JavaScript arrow Page 4 - The DOM Location Object Properties
JAVASCRIPT

The DOM Location Object Properties


In this article we will cover the DOM Location Objects, which are used to set or return information regarding a user’s URL. Often considered an HTML DOM object, it is really more of a JavaScript object, created by the runtime engine. Like other objects, it consists of both Properties and Methods, the former of which we will be discussing today.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
December 01, 2008
TABLE OF CONTENTS:
  1. · The DOM Location Object Properties
  2. · Hash It Up
  3. · Being a Good Host
  4. · Using Href
  5. · Getting the Pathname
  6. · Following Protocol

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
The DOM Location Object Properties - Using Href
(Page 4 of 6 )

The href object is used to retrieve or set the entire URL, unlike the host/hostname objects, which only return the host part. Using the same sample URL as in the previous two examples, we are going to create an alert box to display the current full URL. Here is the code:


<html>

<body>

<script type="text/javascript">

alert(location.href);

</script>

</body>

</html>

This will give us a pop-up alert containing the text:

http://www.devshed.com/jamespayneisawesome.html

Likewise, we could create a page that displays the URL on the page instead of in an alert box in this simple fashion:


<html>

<body>

<script type="text/javascript">

document.write(location.href);

</script>

</body>

</html>

This code gives us a page with this text:

http://www.devshed.com/jamespayneisawesome.html


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 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials