iframe does not have a name attribute, has a id attribute instead. Here is the modified code that is working for me
<script type="text/javascript"> var origOnSelectionChanged = null; function MySelectionHandler(){ origOnSelectionChanged(); var mapFrame = document.getElementById("viewerFrame").contentWindow.GetMapFrame(); var count = mapFrame.GetSelectedCount(); alert(count + " features selected"); } window.onload = function(){ var timer; var watch = function(){ try { var mapFrame = document.getElementById("viewerFrame").contentWindow.GetMapFrame(); if(mapFrame.mapInit){ clearInterval(timer); origOnSelectionChanged = mapFrame.parent.OnSelectionChanged; mapFrame.parent.OnSelectionChanged = MySelectionHandler; } } catch(e) { } }; timer = setInterval(watch, 200); }; </script> document.getElementById("viewerFrame").contentWindow - this returned Window ajaxviewer.aspx?SESSION=86381ee6-ffff-ffff-8000-001ec9fcf959_en_90C340330AF20AF10AF0&WEBLAYOUT=Library://xxxx/xxxxx/xxxx/xxx.WebLayout and this is the only way I was able to get a reference to GetMapFrame() function. document.getElementById("viewerFrame").contentWindow.GetMapFrame() - this returned Window mapframe.aspx?MAPDEFINITION=Library%3a%2f%2fxxxx%2fxxxx%2fMap%2fxxxx.MapDefinition&TYPE=HTML&SHOWLEGEND=0&SHOWPROP=0&INFOWIDTH=0&LOCALE=en&HLTGT=1&HLTGTNAME=&SHOWSLIDER=1&SESSION=11fc683c-0000-1000-8000-001ec9fcf959_en_90C340330AF20AF10AF0 also I had to use .parent to get OnSelectionChanged Event. Out of curiosity, I also tried this in dotnetviewersample.aspx. It worked. There I can replace document.getElementById("viewerFrame").contentWindow with viewerFrame.contentWindow. Looks like this is a difference between iframe and Frameset. Thanks for the responses. ----------------- Jackie Ng wrote: > > you can't use document.getElementById() to access frames, you have to > reference the frame with a variable of the same name, and your > frame/iframe must have its "name" attribute defined > > - Jackie > > > clarkie342 wrote: >> >> After posting my question I did find a reference to the sample you have >> sent below. It was well explained, but it did not work with my code. So I >> tried to add it to the <HEAD> of the dotnetviewersample.aspx. It did not >> work their either. >> >> The problem with my code as I noticed is this javascript is not able to >> get a reference to my viewer frame. >> As I mentioned I am using an iframe with id 'viewerFrame'. My app uses >> master pages and this iframe is inside a contentplaceholder. I also tried >> >> document.getElementById(“viewerFrame”).contentWindow.GetMapFrame(); >> >> came back as object not found. Am I working with the right issues or is >> it all supposed to work irrespective of the frame type? Thanks for any >> help. >> >> >> Jackie Ng wrote: >>> >>> This is javascript code that hooks onto events from the viewer frame. >>> >>> So the code should go in the page that launches the viewer frame. >>> >>> A more detailed explaination here: >>> http://trac.osgeo.org/mapguide/wiki/CodeSamples/JavaScript/AJAXViewerEventHooking >>> >>> - Jackie >>> >>> >>> clarkie342 wrote: >>>> >>>> Hi Jason, >>>> >>>> I am trying to implement your suggestion below to make use of the >>>> OnSelectionChanged Event Handler in mainframe.templ >>>> I have a asp.net page with iframe showing a mapguide map. I want to be >>>> able to do bunch of things when the user selects features on this map. >>>> I am not very clear on how you are implementing your SelectionChanged >>>> function instead of the original one. Where should this script go? >>>> Appreciate your help. >>>> >>>> Thanks >>>> >>>> >>>> Jason Birch wrote: >>>>> >>>>> >>>>> There is an OnSelectionChanged function in the main frame, but it >>>>> doesn't appear to be documented. >>>>> >>>>> I've just tried playing around with this, and I got the following to >>>>> work when inserted into the <head> of the ajaxviewersample.php file. >>>>> It does not appear to work with the DWF viewer; maybe why it's not >>>>> documented? Or it could just be that my code is bad :) >>>>> >>>>> <script type="text/javascript" > >>>>> >>>>> var originalOnSelectionChanged; >>>>> var initTimer = setInterval(watchInitialized, 200); >>>>> >>>>> function watchInitialized () { >>>>> try { >>>>> if(ViewerFrame.mapFrame.mapInit) >>>>> { >>>>> clearInterval(initTimer); >>>>> originalOnSelectionChanged = ViewerFrame.OnSelectionChanged; >>>>> ViewerFrame.OnSelectionChanged = MyOnSelectionChangedHandler; >>>>> } >>>>> } >>>>> catch(Exception) {} >>>>> } >>>>> >>>>> function MyOnSelectionChangedHandler() { >>>>> originalOnSelectionChanged (); >>>>> var mapFrame = ViewerFrame.GetMapFrame(); >>>>> selCount = mapFrame.GetSelectedCount(); >>>>> alert("Selected: " + selCount); >>>>> } >>>>> >>>>> </script> >>>>> >>>>> >>>>> >>>>> ________________________________ >>>>> >>>>> From: Willem Schwarte [mailto:wil...@giskit.nl] >>>>> Subject: [mapguide-users] OnSelection Event? >>>>> >>>>> >>>>> I suppose there is no onSelectionChanged event like in MG6.5. So this >>>>> would be done on a onClick? Where would I put the code for this? >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: users-unsubscr...@mapguide.osgeo.org >>>>> For additional commands, e-mail: users-h...@mapguide.osgeo.org >>>>> >>>> >>>> >>> >>> >> >> > > -- View this message in context: http://n2.nabble.com/OnSelection-Event--tp1804304p2134911.html Sent from the MapGuide Users mailing list archive at Nabble.com. _______________________________________________ mapguide-users mailing list mapguide-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapguide-users