The Global Object

The Global object does not have a constructor and it is not possible to use the global object as a constructor with the new operator.

This object is an exception to the rule that you need to specify the object name when calling its functions. All the functions in this object can be called from anywhere in the script just by using the function name.

Global Object Properties

All Global object properties are read only (they can not be changed or deleted). It is not possible to add new properties to the global object.

Property

Description

Infinity

The value +infinity, This property is read only.

NaN

The value NaN (Not a Number), This property is read only.

undefined

The value undefined, This property is read only.

Global Object Functions

There are a number of functions for encoding and decoding strings for URIs (Universal Resource Indicators). Over the several versions of the ECMAScript standard these have changed. The old encoding/decoding functions are still available here but have been deprecated (this means they will be removed at a later date). All new code should use the non-deprecated versions.

Function

Description

escape(string)

Returns an encoded version of the argument string for a URI.

DEPRECATED. This function is an old version of the URI encoding. It is still available for backward compatibility but may be removed in later releases.

exit()

This terminates all script processing and flushes the output buffer to the browser.

isFinite(number)

Returns false if the value of the number is + or - infinity, and otherwise returns true.

isNaN(number)

Returns true if the value of the number is NaN, and otherwise returns false.

decodeURI(encodedURI)

Returns a new version of a URI in which each escape sequence and UTF-8 encoding of the sort that might be introduced by the encodeURI function is replaced with the character that it represents. Escape sequences that could not have been introduced by encodeURI are not replaced.

decodeURIComponent(

encodedURIComponent)

Returns a new version of a URI in which each escape sequence and UTF-8 encoding of the sort that might be introduced by the encodeURIComponent function is replaced with the character that it represents.

decodeUriComponent(string)

Returns an un-encoded version of the argument string encoded by the encodeUriComponent() function.

 

DEPRECATED. This function is an old version of the URI encoding. It is still available for backward compatibility but may be removed in later releases.

encodeURI(uri)

Returns a new version of a URI in which each instance of certain characters is replaced by one, two or three escape sequences representing the UTF-8 encoding of the character. This function should be used if encoding a complete URI as certain URI characters (e.g. /) are not encoded. The decoded and encoded strings are shown below:

decoded: -_.!~*'();/?:@&=+$,#0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \"%<>\\^`{|}

encoded: -_.!~*'();/?:@&=+$,#0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%20%22%25%3C%3E%5C%5E%60%7B%7C%7D

encodeURIComponent(

uriComponent)

Returns a new version of a URI in which each instance of certain characters is replaced by one, two or three escape sequences representing the UTF-8 encoding of the character. This function should be used if encoding part of a URI (e.g. a query string value). This function should not be used to encode multiple parts or complete URIs as the special characters in the URI are encoded. The decoded and encoded strings are shown below:

decoded: -_.!~*'()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \"%<>\\^`{|};/?:@&=+$,#

encoded: -_.!~*'()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%20%22%25%3C%3E%5C%5E%60%7B%7C%7D%3B%2F%3F%3A%40%26%3D%2B%24%2C%23

encodeUriComponent(string)

Returns an encoded version of the argument string for a URI.

 

DEPRECATED. This function is an old version of the URI encoding. It is still available for backward compatibility but may be removed in later releases.

parseInt(string[, radix])

Returns an integer value dictated by interpretation of the contents of the string argument according to the specified radix. Leading white space in the string is ignored. If radix is undefined or 0, it is assumed to be 10 except when the number begins with the character pairs 0x or 0X, in which case a radix of 16 is assumed. Any radix-16 number may also optionally begin with the character pairs 0x or 0X.

The radix, if present, must be in the range 2 - 35. If outside this range then NaN is returned.

parseFloat(string)

Returns a number value dictated by interpretation of the contents of the string argument as a decimal literal. If the string is not numeric then NaN is returned.

parseQuery(string)

Returns an object holding all the query string parameters from the string argument.

redirect(urlString, [local])

This terminates all script processing, throws away the output buffer and transfers control to the URI defined in the argument. The local argument is an optional boolean value that determines how the redirect is done. If the local argument is false or not present then the redirect is done by sending a redirect page, with the URI embedded in it, to the browser that will then ask for the new page. If the local argument is true then the redirect is done entirely within the server.

A browser redirect will only work for HTML type pages but does allow redirect to any URI, even one not associated with the Active Web servlet.

A server (local) redirect will work for any type of pages but can only redirect to a local server page.

toArray(obj)

Returns an array object. If the obj argument is an array then it is returned. If the obj argument is not an array then a new array is returned with the argument as its first element. If the obj argument is null or not present then a new empty array is returned.

write(string)

Write the argument string to the output buffer. In binary mode if the single object passed to the write() function is a File or BinaryFile object then the bytes represented by the object will be written instead of their string representation.

writeln(string)

Write the argument string followed by a new line code to the output buffer. In binary mode if the single object passed to the write() function is a File or BinaryFile object then the bytes represented by the object will be written instead of their string representation. Note: in binary mode using this function will add one or two bytes to the output depending on platform.

unescape(escapedString)

Returns an un-encoded version of the argument string encoded by the escape() function.

 

DEPRECATED. This function is an old version of the URI encoding. It is still available for backward compatibility but may be removed in later releases.

createSession()

This initiates a servlet session for the purposes of session tracking. Returns true if a session is successfully created or a session already exists. When a session has been created for a client the request object holds a jsession property. See Session Object.

getTmpDir()

Returns a file object representation of a temporary directory which may be used by the application developer.

forward(path)

 

Terminates the script processing, throws away the current output buffer and transfers control to the path supplied. The path can either be relative to the current page executing or absolute under the context path of the executing WebApplication.

This allows a developer to call another server side page that may not contain Active Web. When a page is forwarded to the query string of the forwarding page is included in the request along with any additional query string that may be in the request.

For example if a.xsp is called with empId=2 and it in turn forwards control using forward to b.xsp with an additional parameter of operation=getdetails then b.xsp will effectively be called with the parameters empId=2&operation=getDetails. In the case where the forward call contains a parameter that duplicates and existing query string parameter, then they are presented to the forwarded page as an array.

 

Note.

The path of the forward call may be relative or absolute  to the current page.  When relative care should be taken to not use path mapping access to Active Web – e.g. /concertox instead of a file extension of .xsp.  If the page in which the forward method is used was called via /concertox and the forward request is relative then the forward location will be relative to /concertox and not the full requested URI.

 

The forward() function call is not supported from pages that are called with multipart/form-data parameters.

 

See the Global Object Tutorial for an example.

Comment on this topic

Topic ID: 150101