6 the onnavigaterequest event, Syntax, Example – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual
Page 89

N
AURTECH
W
EB
B
ROWSER AND
T
ERMINAL
E
MULATION FOR
W
INDOWS
CE
AND
W
INDOWS
M
OBILE
CETerm Scripting Guide
Page 89
4.6
T
HE
O
N
N
AVIGATE
R
EQUEST
E
VENT
The OnNavigateRequest event is fired before the browser begins a navigation.
Normally, all navigation control should be done within the HTML of a page. In
rare cases when the pages cannot be modified, this handler can be used to
control navigations. This handler can cancel a navigation or request an
alternative navigation.
Syntax
function OnNavigateRequest ( session, url )
session
– index of browser session.
url
– target URL of navigation request.
The return value of OnNavigateRequest is used to control the navigation. A
return value of 0 will allow the navigation to continue, a value greater than 0 will
cancel the navigation.
Example
This example shows how to control navigation.
/* OnNavigateRequest */
function OnNavigateRequest( session, url )
{
// Prevent unwanted URL
if (url.match( "forbidden.htm" )) return 1;
// Require password
if (url.match( "protected.htm" ))
{
var t = CETerm.TextInput;
t.Title = "Administrator Login";
t.Prompt = "Please enter your password:";
t.PasswordMode = true;
t.Input = ""; // Clear current password
var s = t.GetInput();
if (s !== 1 || t.Input !== "secret")
{
// Bad password, cancel
return 1;
}
t.Input = ""; // Clear password
}