[mapguide-users] Calling viewer api functions from the main page

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Tue Jun 10 05:07:21 EDT 2008


I can clearly see an error in firebug.
It says "parent.imapframe has no properties".
And that is true. The button is running in the same document as the iframe.
Thus the documents parent is the window, and it has no iframes.

You should not rely on getting and entry by using its ID as the variable 
name, as that is not W3C compliant.
You should use document.getElementById() instead.

There exists functions to get the correct frame, use "GetMapFrame()".
I have fixed the code in your example.

To examine what happens, try the following:
1. Start the page in firefox
2. Activate firebug
3. Select the "Script" tab
4. Select the page in the dropdown next to the "inspect" button (topmost)
5. Click next to the number 15 on the right (the line: var iframe = 
document.getElementById('imapframe');)
6. Click the "Refresh" button in the page.
7. Observe the line gets highlighted in firebug
8. On the pane to the right, try to click on "New watch expression..."
9. Try to enter the following (press enter after each): parent, window, 
document.getElementById('imapframe')
10. Examine their properties by clicking the + signs below

You can step to the next line by pressing F10.
On line 23, try to press F11 to step into the function.
Press F8 to resume the javascript.

This is the HTML I used:

<html>
<head>
</head>
<body>

<iframe id="imapframe" frameborder="0" height="600" scrolling="no"
width="800" 
src="/mapguide/mapviewernet/ajaxviewer.aspx?WEBLAYOUT=Library://Samples/Sheboygan/Layouts/SheboyganAsp.WebLayout&USERNAME=Anonymous&PASSWORD="></iframe>

<input type="button" value="refresh" onclick="test()" />

<script type="text/javascript">
function test()
{
    //Get the iframe
    var iframe = document.getElementById('imapframe'); //Set breakpoint here
    //var iframe = imapframe; <-- Non-standard compliant way, but 
usually works

    //Some browsers return the <iframe> tag, others return the contents, 
this evens it out
    if (iframe.contentWindow)
        iframe = iframe.contentWindow;

    //Use the utility function to get the map frame
    iframe.GetMapFrame().Refresh(); //Try F11 here

    //The original code
    //parent.imapframe.mapFrame.Refresh();

    //Alternative, depends on the internal layout of the viewer
    iframe.mapFrame.Refresh();
}
</script>
</body>
</html>

Regards, Kenneth Skovhede, GEOGRAF A/S



A H skrev:
> well there's no error, so firebug didn't detect anything.
>
>
> you can try on this,
>
> this is the iframe,
>
> <iframe id="imapframe" frameborder="0" height="600" scrolling="no"
> width="800" src="/mapguide/mapviewernet/ajaxviewer.aspx?SESSION=<%=
> get_session() %>&WEBLAYOUT=<%= get_layout() %>"></iframe>
>
>
> and a button,
>
> <input type="button" value="refresh" onclick="test()" />
>
>
> and the refresh command,
>
> <script type="text/javascript">
>     function test()
>     {
>         parent.imapframe.mapFrame.Refresh();
>     }
> </script>
>
>
> i've been googling for some time and still haven't find a solution to make
> this work in Firefox.
>
>
>
>
> Kenneth Skovhede, GEOGRAF A/S wrote:
>   
>> If you install firebug, you can inspect the code, and examine the 
>> objects you are calling:
>> http://www.getfirebug.com/
>>
>> Next step would be to look at "MapGuide Developers Guide" page 19:
>> http://mapguide.osgeo.org/2.0/documentation.html
>>
>> You can see how the viewer frames are laid out, and see what 
>> "parent.parent" points to.
>> Page 18 describes what the frames are for and page 20-25 describe 
>> concrete cases.
>>
>> Regards, Kenneth Skovhede, GEOGRAF A/S
>>
>>
>>
>> A H skrev:
>>     
>>> sadly this doesn't work in Firefox. have anyone done this in Firefox?
>>>
>>>
>>>
>>> uXuf wrote:
>>>   
>>>       
>>>> Okay thanks. parent.viewerFrame.mapFrame works like a charm!
>>>>
>>>> uXuf
>>>>
>>>>
>>>> Ivan Milicevic-3 wrote:
>>>>     
>>>>         
>>>>> try parent.viewerFrame.mapFrame.Refresh(); od
>>>>> window.frames.mapFrame.Refresh();
>>>>>
>>>>> ________________________________
>>>>>
>>>>> From: mapguide-users-bounces at lists.osgeo.org on behalf of uXuf
>>>>> Sent: uto 8.1.2008 22:43
>>>>> To: mapguide-users at lists.osgeo.org
>>>>> Subject: [mapguide-users] Calling viewer api functions from the main
>>>>> page
>>>>>
>>>>>
>>>>> Hi all, I am trying to access the Viewer API functions from the main
>>>>> page
>>>>> of my application, i.e. the page that has the WebLayout embedded (or
>>>>> the
>>>>> iframe). I cannot seem to grab the exact frame from which these
>>>>> functions
>>>>> would be accessible. I tried using
>>>>> document.getElementById("viewerFrame").GetMapFrame() (viewerFrame is
>>>>> the
>>>>> name of the iframe) putting it in the onload function of the iframe but
>>>>> it returns "Object doesn't support this property or method". Can anyone
>>>>> help me in this regard? Thanks! uXuf 
>>>>>
>>>>> ________________________________
>>>>>
>>>>> View this message in context: Calling viewer api functions from the
>>>>> main
>>>>> page
>>>>> <http://www.nabble.com/Calling-viewer-api-functions-from-the-main-page-tp14699670s16610p14699670.html> 
>>>>> Sent from the MapGuide Users mailing list archive
>>>>> <http://www.nabble.com/MapGuide-Users-f14845.html>  at Nabble.com.
>>>>>
>>>>>
>>>>>  
>>>>> _______________________________________________
>>>>> mapguide-users mailing list
>>>>> mapguide-users at lists.osgeo.org
>>>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>>
>>>>>
>>>>>       
>>>>>           
>>>>     
>>>>         
>>>   
>>>       
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>
>>
>>     
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20080610/a1f11db3/attachment.html


More information about the mapguide-users mailing list