Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

The Location Object

When you load a Web page into your browser, the path or URL to that page is stored in the window.location object. You can retrieve the page's URL from the location object, or you can load a different page into the window by using the location object's assign or replace methods.

Location Object Properties

href The URL of the current page
protocolThe URL's protocol, usually http:
host The hostname and port number
hostnameThe name of the host
pathnameThe path relative to the current directory
port The port number (default http port is 80)
hash An inpage anchor (#) attached to URL
search A query string (?) attached to URL

Location Object Methods

reload() Reloads the current page
replace("URL") Loads the specified URL and disables the Back button
assign("URL") Loads the specified URL, does not disable the Back button

The example code below shows the location object's replace method being executed by the document's onload event. This causes the webpage to be replaced by the page at the specified URL immediately after it completes loading.

<body onload="window.location.replace('page2.htm')">

Note the same action can be performed without Java Script using a refresh meta tag with its content attribute set to 0, as shown below.

<meta http-equiv="refresh" content="0;url=page2.htm">

More Java Script Code:
• Using the Java Script eval() Function
• Java Script Trigonometric Methods
• The for Loop
• The break Statement
• The Java Script window.open Method
• JavaScript .big and .small to Change Text Size
• Java Script Math.sin Method
• The while Loop
• Interactively Set Webpage Colors
• Search and Replace Strings

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2018 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268