none
Webbrowser control + Toolkit Contextmenu?

    Question

  • Hi,
    i was wondering if it is possible to add a contextmenu to the webbrowser control?

    Thanks in advance!
    Wednesday, February 16, 2011 7:03 AM

All replies

  • It appears that the Silverlight Webbrowser, which is inherited by the Phone, doesn't support .ContextMenu.

    http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser(v=VS.95).aspx

    But you might be able to simulate this using adjacent or overlaying controls.

    Hope this helps,
    Mark
    Wednesday, February 16, 2011 5:30 PM
  • Thanks,
    also do you know any way i could take a screenshot using WriteableBitmap of the webbrowser control?

    I was able to take an image from any control but this one.

    Thanks in advance!
    Wednesday, February 16, 2011 9:52 PM
  • Hi Exawire,

    This is a known issue and it is being tracked in our issues database. Whether it will be enabled in the future is undetermined at this time.

    - Mark
    Wednesday, February 16, 2011 10:49 PM
  • In the current implementation of Silverlight for Windows Phone, it's best to think of the web browser control as an "island" independent of the rest. We composite the browser control in the visual tree, but it isn't something that can be bridge both - you cannot hook up to Silverlight manipulation events for the browser control and intercept them, for example, which is why context menu does not work.

    Same goes for taking a screenshot / writeable bitmap of the control.

    Like Mark says, we're always thankful for the feedback and take that into account in planning for new work. 
    Sunday, February 20, 2011 6:27 PM
  • There must be some work around. If anyone has used the surfcube app, it has a context menu for when you hold and press on links. It does invoke javascript but I am not sure what that code is. If anyone does figure this out though let us know.
    Monday, June 13, 2011 4:07 AM
  • Hey everyone,

    It is possible to have a contextmenu for the browser using invokescript. The browser on the emulator does eat all document events and what not but the actual phone does not! I have a contextmenu in my browser.
    Tuesday, June 21, 2011 7:19 PM
  • To add more to this. Taking a writablebitmap of webbrowser control isnt supported on the desktop Silverlight either(AFAIK). However, there is a concept of WebBrowserBrush, which isnt currently supported on Mango.

    Thanks
    Rohan
    Tuesday, June 21, 2011 9:28 PM
  • Hey everyone,

    It is possible to have a contextmenu for the browser using invokescript. The browser on the emulator does eat all document events and what not but the actual phone does not! I have a contextmenu in my browser.

    Hey, GINtech Systems would you mind posting a code example of how you achieved this?
    Monday, August 08, 2011 5:58 AM
  • Hi,

    Context Menu is not supported in windows phone 7 in web browser control.

    Monday, August 08, 2011 6:33 AM
  • Hi,

    Context Menu is not supported in windows phone 7 in web browser control.


    Yes but it has been done in an app called SurfCube and I was wondering if anyone knows how it was accomplished.
    Monday, August 08, 2011 11:34 PM
  • Hi,

    Context Menu is not supported in windows phone 7 in web browser control.


    Yes but it has been done in an app called SurfCube and I was wondering if anyone knows how it was accomplished.

    Yes it can be done, here is the code. Sorry for such a long late delay, hopefully this still helps.

    public void AttachContextMenu()
            {
                try
                {
                    if (GINternet.IsScriptEnabled)
                    {
                        GINternet.InvokeScript("execScript", "function FindParentLink(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'a') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentLink(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction FindParentImage(item) \r\n{\r\n\tif (!item.parentNode)\r\n\t\treturn null;\r\n\tif (item.tagName.toLowerCase() == 'img') \r\n\t{\r\n\t\treturn item;\r\n\t} \r\n\telse \r\n\t{\r\n\t\treturn FindParentImage(item.parentNode);\r\n\t}\r\n}\r\n\r\nfunction HandleContextMenu() \r\n{\r\n\tvar linkItem = FindParentLink(event.srcElement);\r\n    var imageItem = FindParentImage(event.srcElement);\r\n    var notifyOutput = '';\r\n    if (linkItem != null) if (linkItem.href != null) notifyOutput += linkItem.href;\r\n    if (imageItem != null) if (imageItem.src != null) notifyOutput += imageItem.src;\r\n    if (notifyOutput != '')\r\n        window.external.notify(notifyOutput);\r\n    else\r\n\t\twindow.external.notify('NOTLINKIMG');\r\n}");
                        GINternet.InvokeScript("execScript", "document.oncontextmenu = HandleContextMenu;");
                    }
                }
                catch
                {
                }
            }

    Saturday, December 03, 2011 5:52 PM