JavaScript
  Home arrow JavaScript arrow Page 4 - Methods of the DOM Location Object
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Methods of the DOM Location Object
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-12-08

    Table of Contents:
  • Methods of the DOM Location Object
  • Assign() Gives You Tasks
  • The Jatrix…Reloaded()
  • Replace()

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    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.

     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek