Cari di JavaScript 
    JavaScript Manual
Daftar Isi
(Sebelumnya) Chapter 12. Utilities, File, S ...Debug, deleteResponseHeader, e ... (Berikutnya)

Chapter 13
Global Functions

This chapter contains all JavaScript functions not associated with any object.

Table 13.1 summarizes these functions.

Table 13.1 Global functions

FunctionDescription
addClient 
Appends client information to URLs.

addResponseHeader 
Adds new information to the response header sent to the client.

blob
Assigns BLOb data to a column in a cursor.

callC 
Calls a native function.

debug 
Displays values of expressions in the trace window or frame.

deleteResponseHeader
Removes information from the header of the response sent to the client.

escape
Returns the hexadecimal encoding of an argument in the ISO Latin-1 character set; used to create strings to add to a URL.

eval
Evaluates a string of JavaScript code without reference to a particular object.

flush 
Flushes the output buffer.

getOptionValue 
Gets values of individual options in an HTML SELECT form element.

getOptionValueCount 
Gets the number of options in an HTML SELECT form element.

isNaN
Evaluates an argument to determine if it is not a number.

Number
Converts an object to a number.

parseFloat
Parses a string argument and returns a floating-point number.

parseInt
Parses a string argument and returns an integer.

redirect 
Redirects the client to the specified URL.

registerCFunction 
Registers a native function for use in server-side JavaScript.

ssjs_generateClientID
Returns an identifier you can use to uniquely specify the client object.

ssjs_getCGIVariable
Returns the value of the specified environment variable set in the server process, including some CGI variables.

ssjs_getClientID
Returns the identifier for the client object used by some of JavaScript's client-maintenance techniques.

String
Converts an object to a string.

taint
Adds tainting to a data element or script.

unescape
Returns the ASCII string for the specified value; used in parsing a string added to a URL.

untaint
Removes tainting from a data element or script.

write 
Adds statements to the client-side HTML page being generated.


addClient

Adds client object property values to a dynamically generated URL or the URL used with the redirect function.

Server-side function

Implemented in

LiveWire 1.0

Syntax

addClient(URL)

Parameters

URL
A string representing a URL

Description

The addClient function is a top-level server-side JavaScript function not associated with any object.

Use addClient to preserve client object property values when you use redirect or generate dynamic links. This is necessary if an application uses client or server URL encoding to maintain the client object; it does no harm in other cases. Since the client maintenance technique can be changed after the application has been compiled, it is always safer to use addClient, even if you do not anticipate using a URL encoding scheme.

See Writing Server-Side JavaScript Applications for information about using URL encoding to maintain client properties.

Examples

In the following example, addClient is used with the redirect function to redirect a browser:

redirect(addClient("mypage.html"))
In the following example, addClient preserves client object property values when a link is dynamically generated:

<A HREF='addClient("page" + project.pageno + ".html")'>
   Jump to new page</A>

See also

redirect


addResponseHeader

Adds new information to the response header sent to the client.

Server-side function

Implemented in

Netscape Server 3.0

Syntax

addResponseHeader(field, value)

Parameters

field
A field to add to the response header.

value
The information to specify for that field.

Description

You can use the addResponseHeader function to add information to the header of the response you send to the client.

For example, if the response you send to the client uses a custom content type, you should encode this content type in the response header. The JavaScript runtime engine automatically adds the default content type (text/html) to the response header. If you want a custom header, you must first remove the old default content type from the header and then add the new one. If your response uses royalairways-format as a custom content type, you would specify it this way:

deleteResponseHeader("content-type");
addResponseHeader("content-type","royalairways-format");
You can use the addResponseHeader function to add any other information you want to the response header.

Remember that the header is sent with the first part of the response. Therefore, you should call these functions early in the script on each page. In particular, you should ensure that the response header is set before any of these happen:

  • The runtime engine generates 64KB of content for the HTML page (it automatically flushes the output buffer at this point).
  • You call the flush function to clear the output buffer.
  • You call the redirect function to change client requests.

See also

deleteResponseHeader


blob

Assigns BLOb data to a column in a cursor.

Server-side function

Implemented in

LiveWire 1.0

Syntax

blob (path)

Parameters

path
A string representing the name of a file containing BLOb data. This string must be an absolute pathname.

Returns

A blob object.

Description

Use this function with an updatable cursor to insert or update a row containing BLOb data. To insert or update a row using SQL and the execute method, use the syntax supported by your database vendor.

On DB2, blobs are limited to 32 KBytes.

Remember that back slash ("") is the escape character in JavaScript. For this reason, in NT filenames you must either use 2 backslashes or a forward slash.

Example

The following statements update BLOb data from the specified GIF files in columns PHOTO and OFFICE of the current row of the EMPLOYEE table.

// Create a cursor
cursor = database.cursor("SELECT * FROM customer WHERE
   customer.ID = " + request.customerID
// Position the pointer on the row
cursor.next()
// Assign the blob data
cursor.photo = blob("c:/customer/photos/myphoto.gif")
cursor.office = blob("c:/customer/photos/myoffice.gif")
// And update the row
cursor.updateRow("employee")

callC

Calls an external function and returns the value that the external function returns.

Server-side function

Implemented in

LiveWire 1.0

Syntax

callC(JSFunctionName, arg1,..., argN)

Parameters

JSFunctionName
The name of the function as it is identified with RegisterCFunction.

arg1...argN
A comma-separated list of arguments to the external function. The arguments can be any JavaScript values: strings, numbers, or Boolean values. The number of arguments must match the number of arguments required by the external function.

Description

The callC function is a top-level server-side JavaScript function that is not associated with any object.

The callC function returns the string value that the external function returns; callC can only return string values.

Examples

The following example assigns a value to the variable isRegistered according to whether the attempt to register the external function echoCCallArguments succeeds or fails. If isRegistered is true, the callC function executes.

var isRegistered =
   registerCFunction("echoCCallArguments",
      "c:/mypath/mystuff.dll",
      "mystuff_EchoCCallArguments")
if (isRegistered == true) {
   var returnValue =
   callC("echoCCallArguments", "first arg", 42, true, "last arg")
   write(returnValue)
}

See also

registerCFunction

(Sebelumnya) Chapter 12. Utilities, File, S ...Debug, deleteResponseHeader, e ... (Berikutnya)