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

Usenet News (News)

The News URL scheme allows you to refer to Usenet newsgroups or specific articles in such a newsgroup. The syntax is either one of the following:


news:<newsgroup-name>
news:<message-id>

The newsgroup-name is the Usenet’s newsgroup name (e.g., comp.lang.javascript) from which all title articles will be retrieved by the browser (a maximum number may be specified in the browser setup). message-id corresponds to the Message-ID of a specific article to obtain. It is found in the article’s header information.

Host-Specific File Names (File)

The File URL scheme indicates a file which can be obtained by the client machine. The syntax for the File scheme is:

file://<host>:<path>

The host is the fully qualified domain name of the system, and the path is the hierarchical directory path to the required file. Leave host empty or specify “localhost” to refer to the client’s local files.

JavaScript Statements (javascript)

The JavaScript URL scheme is quite different. Its general syntax is:

javascript:<valid-javascript-statement-expression-command>

This scheme evaluates the expression after the colon. If the expression can be evaluated to a string, a new page is opened and the string displayed. If the expression is undefined, a new page does not open.

Other Schemes

There are probably over ten other schemes that are far beyond the scope of this book. Bear in mind that we are dealing with JavaScript, so we only focus on schemes that might be needed in a script.

location Object

The location object represents a complete URL. Therefore, it is a property of the window object. As always, specifying the window object when referring to a property or a method of location is optional. Each property of the location object represents a different portion of the URL. The following syntax of a URL shows the relationship between the object’s properties:

protocol//hostname:port pathname search hash

The location object belongs to the window containing the JavaScript script. Single-frame pages have only one location object. However, pages that use multiple frames consist of a window.location (location) object for each frame, as well as one for the main frameset document. For example, a page with two frames consists of three URLs, and a location object is available for each.

Because window is a default object in scripts, you can use location rather than window.location. However, if you use this object to specify an event handler script, you must specify the full window.location. Due to the scoping of static HTML objects in JavaScript, a call to location without specifying an object name is equivalent to document.location, which is currently a synonym for document.URL. You should avoid document.location because it will not be supported in the future.

location Properties

As you know, the location object consists of both properties and methods. The methods were added later, debuting in Navigator 3.0. In this section we shall take a look at the object’s properties, basing the discussion on the previous section, “A Crash Course in URLs.”

href

The href property is the most popular one in HTML scripting. The identifier “href” stands for hypertext reference. This property supplies a string of the entire URL of the calling window object. This property is for both reading and setting. By assigning a string to this property, you can change the URL of the page in the window. For example, if you want to load Netscape’s homepage when the user clicks a button, you can use the following syntax:

<HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--

function load() {
 location.href = 'http://www.netscape.com'
}

// -->
</SCRIPT>
<FORM>
<INPUT TYPE="button" VALUE=" load page " onClick="load()">
</FORM>
</HTML>

You can also retrieve the full URL of the current window (the current window object to be exact) by reading the URL value. For example, if you want the full URL of the current file, not including the filename itself, you can use the following script segment:

var url = location.href
var lastSlash = url.lastIndexOf("/")
var partialURL = url.substring(0, lastSlash + 1)

For example, if an HTML document with these three statements is located at <URL:http://www.geocities.com/SiliconValley/9000/ links.html>, partialURL is the string http://www.geocities.com/ SiliconValley/9000/. The problem with this script is that it is not guaranteed to work on a client computer running Windows and MSIE. The reason is that MS chose to stick to the regular Windows’ backslash-based path syntax instead of the Unix slash-based one.

Because href is the most popular among the location object’s properties, it is also the default one. That is, you can specify location or window.location in place of location.href or window.location.href.

Take a look at the following script:

var location = "Ben"

This statement does not generate any error because location is not a reserved word. However, it deletes the location object inside the function in which location is assigned. Since location is not a browser object but rather a simple variable, it is fully accessible from outside the function.

Previous Table of Contents Next


With any suggestions or questions please feel free to contact us