Online Documentation Server
 ÏÎÈÑÊ
ods.com.ua Web
 ÊÀÒÅÃÎÐÈÈ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ÏÎÄÏÈÑÊÀ

 Î ÊÎÏÈÐÀÉÒÀÕ
Âñÿ ïðåäîñòàâëåííàÿ íà ýòîì ñåðâåðå èíôîðìàöèÿ ñîáðàíà íàìè èç ðàçíûõ èñòî÷íèêîâ. Åñëè Âàì êàæåòñÿ, ÷òî ïóáëèêàöèÿ êàêèõ-òî äîêóìåíòîâ íàðóøàåò ÷üè-ëèáî àâòîðñêèå ïðàâà, ñîîáùèòå íàì îá ýòîì.




Previous Table of Contents Next

location Methods

The location object (window.location) also consists of a several methods. These methods are not supported by Microsoft Internet Explorer 3.0 or Netscape Navigator 2.0x. They will surely be supported in future releases of MSIE and are already featured in Navigator 3.0.

reload

The location.reload method forces a reload of the window’s current document. Its general syntax is:

location.reload([true])

Specifying the Boolean value true as the method’s optional argument forces an unconditional HTTP GET of the document from the server. An unconditional GET retrieves a document directly from the server, ignoring the content of the browser’s cache, which might already contain the desired data from that document. Therefore, true specification should not be used unless you have reason to believe that either disk or memory cache is broken, or the server has a new version of the document. If such a version is available, you must force an unconditional HTTP GET because the version of the document stored in cache is different from the new version on the server. This situation is common to CGI-generated documents.

The reload() method simply reloads the document its URL stored in location.href. It uses the same policy as the “reload” or “refresh” button. Microsoft has opted to label the button “refresh” rather than “reload,” but will probably keep the same method names. The exact reload policy depends on the cache handling menu option. In Netscape Navigator, the user sets the default value of this policy by choosing Network Preferences from the Options menu, and specifying Verify Documents on the Cache tab of the Preferences dialog box.

The reload() method does not force a transaction with the server under normal conditions. However, if the user has set the preference to “Every Time,” the request is an unconditional GET using an “if-modified-since” HTTP header. HTTP headers are passed to the browser when a document is retrieved from the server. It contains important information regarding the current document. If the user sets the preference to “Every Time,” the browser checks the transmitted HTTP header to see if the document has been updated according to the “last-modified time” property. If it has, the document cannot be loaded from the cache which holds a previous version of the file. In short, reload() will bring the cache’s version unless the user has specified “Every Time” and (&&) the document has changed on the server since the last time it was loaded and saved in the cache. Since its size is limited, the cache might lose a document version that has not been reloaded for a long time. In this case, the document needs to be fully loaded from the server, even if it has not been changed since the previous load.

In event handlers, you must specify window.location.reload() instead of simply using location.reload(). Due to the static objects’ scoping in JavaScript, a call to location without specifying an object name is equivalent to a call to document.location, which is a synonym for document.URL. This concept is explained later in the chapter in greater detail.

You have probably experienced situations in which you leave your computer connected to a host and go out for a break, then come back to find that the connection has been dumped. The usual cause is that the host (server) has disconnected you because you have not transmitted any data via the server for a long time. You can overcome this problem by periodically reloading a JavaScript document from the server. Next time you go out for lunch, load the following document in the browser’s window:

<HTML>
<HEAD>
<TITLE>stay connected</TITLE>
</HEAD>
<!-- 200000 milliseconds == 200 seconds -->
<BODY
onLoad="timerID = setTimeout('window.location.reload(true)',200000)">
</BODY>
</HTML>

Example 19-4 (ex19-4.htm). A simple HTML document keeps the connection alive.

The onLoad event handler is used to call the reload() method. A setTimeout() method delays the reload procedure for 200,000 milliseconds, or 200 seconds, from the moment the document is completely loaded. Since it is used in the form of an event handler, the reload() method must be fully specified, including the window object reference. The true argument forces the transaction with the server.

replace

The replace() method is also a property of the location, or window.location, object. It overwrites the current history entry with the specified URL. The current history entry is the most recent URL added to the history list, or the URL of previous page loaded. This is the URL that is retrieved when the user presses Back, provided that the “forward” button is dimmed out. The general syntax of the replace() method is as follows:

location.replace("URL")

After the replace() method is used, the user cannot navigate to the previous URL via the Back button. Once again, bear in mind that event handlers require a full method specification.

Suppose you want the user to load page B by clicking a link on page A. Instead of using a plain hypertext link, you can invoke this method to load page B (using the URL of page B as the argument). Once page B has loaded, the user cannot return to page A via the Back button.

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us