The JavaScript Diaries: Part 10

By Lee Underwood

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >


This property returns the path portion of the URL, i.e., everything after the domain name. For instance, if the URL is "", then this property would return the string as "/programming/javascript/." If it's the root directory, then the property would return a slash, "/". An example of its use would be:



This property returns the port portion of the URL. These generally aren't used today. If you've been around the Web awhile, you'll remember them from 'way back when.' An example of its use would be:



This property returns the protocol portion of the URL. That's the portion up to the first colon. It's the method by which the URL is accessed, i.e. http or ftp. An example of its use would be:



This property returns the string following — and including — the question mark in a search query. You might have something like: This property would return: ?v=glance&s=electronics. An example of its use would be:




This method is used to reload the current page in the browser. It's a little more powerful than using the reload button on the browser. It's also a little less dependable. When reloading a page with filled-in form fields, this method will clear the form fields and reload the page, just like holding down the [SHIFT] key and pressing the reload button in the browser. Sometimes, just using the reload() method will perform a reload from the cache, keeping the form intact. Using reload(true) will cause the page to be reloaded from the server, erasing the contents of the form fields and loading a fresh copy of the page. An example of this method in use would be:



This method replaces the current page entry in the browser's history list so a user cannot navigate back to it. How is that useful? If you have a page that's accessed by a password or registration, you might not want the user navigating directly back to it. Using this method, there won't be any trace of that page's URL in the browser's history list. An example of its use would be:

<input type="Button" name="change" value="Change page"

If you load the example above, when you click on the button you will load the index page at the URL listed. You will notice that, although you have gone to another page, you won't be able to return to the previous page as it's not listed in the browser's history. Check your browser's history. You will see the page you visited before loading the file with the script and the one listed in the replace() method but you won't see the page with the script listed. (Be careful when using this method as users generally like to navigate back to pages they have previously visited.)

We should get used to placing these events into functions and then just calling them from the page. Using the last example above, we could write it as follows. Place this code in the head section:

function changePage() {

Then place this in the body section:

  <input type="button" value="Change page"'



That wraps up our study of the navigator, screen, history, and location objects. Remember to use these in your scripts when you need to find out information about the user's environment.

Next time we'll take a look at arrays. After that, we will start looking at the DOM (Document Object Model). That's when things should really start to get interesting. Until then — keep on scripting!

This article originally appeared on

Page 5 of 5

Previous Page
1 2 3 4 5

Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
Thanks for your registration, follow us on our social networks to keep up-to-date