Use this technique when you want to call the API directly from the tool bar.
For example, you may want to create a tool bar button that zooms and positions the map to show a particular location. In the web layout, create a command of type Invoke Script. Enter the API call as the script to invoke:
ZoomToView(-87.7116768, 43.7766789973, 5000, true);
When a user clicks the button, the map view will reposition to the location.
Commands of type Invoke Script always execute in the context of the main frame. This means that all main frame functions are available. To execute a function in another frame, use the frame name as part of the function name. For example, formFrame.Submit().
To add your own JavaScript functions, you can embed a Viewer in another page. See Embedding a Viewer in Your Own Page for details. In this case, any JavaScript functions defined in the outer page are available to scripts as parent. functionName (), where functionName is the name of your function.