Home arrow JavaScript arrow Page 4 - 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 - Replace()
(Page 4 of 4 )

The replace() method is used to replace the current document or page with a new one. I was hoping I could get this code to loop through fifty web pages (without using a loop) but it did not work in that manner. If you use document.write and use replace, it automatically loads a new page; if you put say…ten of those pointing to different URLs, it doesn't display one after another (or if it does, you don’t see that). Instead, it takes a really long time to load the last page.

Here is how you use it in a document.write, instantly loading the page without giving the user a choice (which, by the way, I don’t really recommend):


<html>

<head>

<script type="text/javascript">

document.write(window.location.replace("http://www.devhardware.com"));

 

</script>

</head>

</html>

Now let’s give the user a choice, shall we?

<html>

<head>

<script type="text/javascript">

function replacer()

{

window.location.replace("http://www.devhardware.com");

}

</script>

</head>

<body>

<input type="button" value="Use the replace() Method" onclick="replacer()" />

</body>

</html>

Again, when the user clicks the button, it triggers the replacer() function, which initiates the replace() method, loading the new page. Here is the result:


Conclusion

As you can see, we’ve run out of time, so while we have finished our conversation regarding the Dom Location Objects and Methods, we will have to save the History Objects for a later time. Before we go, however, I would like to leave you with one last review of the tables summarizing the purposes of the Object method and properties we have covered in these two articles. Feel free to print it out and use it as a reference:


Name

What It Does

Type

hash

Used to Set or retrieve the URL starting from the hash (#) symbol

Property

host

Used when you want to set or retrieve the port number and hostname of the URL

Property

hostname

Used to set or retrieve the hostname of the present URL

Property

href

Used to retrieve or set the entire URL

Property

pathname

Used to retrieve or set the pathname of the present URL

Property

port

Used to retrieve or set the port number of the present URL

Property

protocol

Used to retrieve or set the protocol of the present URL

Property

search

Used to retrieve or set the URL from the question (?) mark

Property

assign()

Used when you wish to load a new document/page

Method

reload()

Used when you want to reload the current page/document

Method

replace()

Used when you wish to replace the current page/document with a new one

Method

Till then…


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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