Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

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:
• The break Statement
• Java Script Strings
• A Brief History of JavaScript
• Java Script Math.sin Method
• Determine Minimum and Maximum
• The Document Object Model (DOM)
• Access Web Page Elements With getElementById
• Comparison Operators
• Java Script Reserved Words
• Remove Blank Spaces From Ends of a String

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-2024 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268