[[PageOutline]] This page is one of the !MapGuide Community CodeSamples. Visit the CodeSamples page to view more! == Hooking to events in the AJAX viewer == The AJAX viewer in its current form is quite limited in terms of customizability. It would be nice if you could listen to capture certain events in the ajax viewer and add on your custom javascript. This page will show how to do the following: * Checking when the map has been loaded. * Handling viewer selection. It is assumed you know what anonymous functions are and how they work. == Checking when the map has been loaded == Before we can hook on to events in the ajax viewer, we need to check that the DOM for the ajax viewer has been loaded. This sample shows how to do it. Assume your viewer page looks something as follows: {{{ #!text/html Viewer Sample Application }}} Insert the following script block in the head of the page: {{{ #!text/html }}} == Handling viewer selection == This sample will show how to handle the selection in the ajax viewer. This assumes the html is the same as the previous example. The code "overrides" the OnSelectionChanged function of the map frame (this is called by the map frame when selection changes) and replaces it with our own. Insert the following script block in the head of the page: {{{ #!text/html }}} when you make a selection on the map, the code will display a dialog showing how many features were selected. Note: Our custom handler executes when a selection has changed. So clearing the selection, for example will also call the handler even though we haven't actually made a selection.