![]()
Step 8 - JavaScript
To enable the JavaScript scripter, ib6js.jar must be included in the classpath. The application is responsible for handling alerts and other requests for user inputs from JavaScript scripts. To handle such callbacks the application must implement the ice.storm.ScripterCallback interface and register it with the browser.
The ScripterCallback implementation must handle the following events:
- Decide how long a script is allowed to block user input, and if this time is exceeded, whether the script should be terminated.
- Decide whether the script is allowed to close windows.
- Inform the user about script errors.
- Display alert messages and implement user input dialogs.
In the tutorial, MyScripterCallback is the custom implementation of the ScripterCallback interface. The main method is modified as follows:
stormBase.setViewportCallback(new MyCallback()); stormBase.setScripterCallback(new MyScripterCallback()); stormBase.addPropertyChangeListener(new VisitedLinks(), null); stormBase.renderContent(location, null, "MyBrowser");The scripterCallback implementation looks like the following:
class MyScripterCallback implements ScripterCallback { public boolean allowScriptClose( Viewport viewport, boolean openedByScript) { return true; } public long getMaxScriptRunningTime() { return 5000; } public boolean interruptLongRunningScript( Viewport viewport, long scriptRunTime) { return true; } public void reportScriptError( Viewport viewport, boolean justWarning, String errorMessage, String url, int lineNumber, String lineSource, int lineOffset) { // do nothing. } public void scriptAlert(Viewport viewport, String alertMessage) { showAlert(viewport, alertMessage); } public boolean scriptConfirm( Viewport viewport, String confirmationMessage) { return showConfirmation(viewport, confirmationMessage); } public void scriptPrint(Viewport viewport) { System.out.println("window.print is called from script"); } public String scriptPrompt( Viewport viewport, String promptMessage, String defaultValue) { return showPrompt(viewport, promptMessage, defaultValue); } }The functions showAlert( ), showConfirmation( ), showPrompt( ) and their supporting functions and members are not shown here. Their implementations can be found in the tutorial source code.
|
Copyright 2005. ICEsoft Technologies, Inc. http://www.icesoft.com |