SHARE
Facebook X Pinterest WhatsApp

HTML Goodies: Script Tip: Week 9

Written By
thumbnail
Joe Burns
Joe Burns
Jan 4, 2005

You there, Tippy!

We’re slowly getting to the bottom of this script. Now we’ll get into the history statement right at the end and wrap it up. Here’s the script so you can familiarize yourself again:







<SCRIPT LANGUAGE=”javascript”>


function JemWebCONFIRM()

{if (!confirm (“YOUR MESSAGE GOES HERE”))
history.go(-1);return ” “}


</SCRIPT>






If you’ve used any of the 3- or 4-level Navigator or Explorer browsers, then you’ve probably already seen this “history” in action. You go up to the location bar at the top of the browser and type in part of a URL and poof! The remainder of the address just pops up.

But how does the browser know that? It knows it because every place you go, in the order you go, is kept in a file called “history.” So, when you start to type in a URL, if you type in something that’s similar to an address that’s already in the history folder, the browser attempts to be nice and finish it off for you.

What’s nice about that history file is that JavaScript sees it as an object to be acted upon. In the case of this script, the method that acts upon it is “go.” That tells the browser to, well, go to the URL.

Notice in this script that not only is the browser being told to go somewhere within the history file, it is being told to go somewhere specific. In this case it is to go one back. See that (-1)?

Well, if that’s the case, then you should be able to tell the browser to jump three back, or four ahead (by using the plus sign instead of the minus). You can. As long as the user has surfed enough to have that many pages in their history file, it’ll work just fine. The problem comes in when you say to jump back four pages and the user has only visited three. The JavaScript cannot complete the command and it all comes to a standstill.

And That’s That

So, now you’ve seen another script explained note for note. Look at it again and see if you are not now starting to see the process of JavaScript. There is a real order to things that you have to understand before you can start writing your own scripts. Here, again, are the steps in the script:


  • You log into the page and the script is loaded into the browser.
  • The function is enacted upon the loading of the page.
  • A confirm box pops up with text written on it.
  • If the person chooses OK, the script is done and the page loads.
  • If the person chooses Cancel, then the history.go is enacted and the browser goes one page back or reloads the page the user just came from.

Next Week: A New Script! Browser Choice



     Do YOU have a Script Tip you’d like to share? How about suggesting a Script Tip to write about? I’d love to hear it. Write me at: jburns@htmlgoodies.com.


Learn to write your own JavaScripts with the
JavaScript Goodies!



You can find many other uses for JavaScript
on your Web pages here!

Recommended for you...

The Revolutionary ES6 Rest and Spread Operators
Rob Gravelle
Aug 23, 2022
Ahead of Time (AOT) Compilation in Angular
Tariq Siddiqui
Aug 16, 2022
Converting a JavaScript Object to a String
Rob Gravelle
Aug 14, 2022
Understanding Primitive Type Coercion in JavaScript
Rob Gravelle
Jul 28, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.