The Hello Viewer sample, installed with the Developer’s Guide samples, shows simple examples of using the Viewer API from different parts of a web layout.
The tool bar for the sample contains a custom Invoke Script command that calls the ZoomToView() function of the mapFrame. This is executed in the context of the main frame, so the function is available using
mapFrame.ZoomToView()
The task pane loads a page that shows two other ways of calling ZoomToView(). One way loads a custom page into the hidden scriptFrame. The page reads GET parameters and passes them to the JavaScript function call. This is executed in the context of the scriptFrame, so ZoomToView() is available using
parent.mapFrame.ZoomToView()
Another way calls ZoomToView() directly when a link is clicked, using the JavaScript onclick event. This is executed in the context of the taskPaneFrame, so ZoomToView() is available using
parent.parent.mapFrame.ZoomToView()
The Developer’s Guide samples also demonstrate a more advanced method for using JavaScript in a Viewer. The file index.php includes an external JavaScript file that solves 2 problems:
To deal with these problems, the Hello Viewer sample loads pageLoadFunctions.js, which attaches a function to the window.onload event of the page in the task pane. This function does the following:
See the Hello Viewer sample for links to view index.php and pageLoadFuctions.js.