c# - Adding contextmenu to WP8 browser control -
i trying attach context menu when user perform hold gesture on link on webpage.
i've searched web , found recommendations here
if (webbrowser.isscriptenabled) { webbrowser.invokescript("execscript", "function eventlistener(evt){ if (evt.type == 'mspointerdown') { gesturehandler.addpointer(evt.pointerid); return; } if (evt.detail & evt.msgesture_flag_end) { window.external.notify(evt.srcelement.tagname);}}"); webbrowser.invokescript("execscript","document.addeventlistener('msgesturehold', eventlistener, false); document.addeventlistener('mspointerdown', eventlistener, false); gesturehandler = new msgesture(); gesturehandler.target = document.body;"); } but second execscript raised error
system.systemexception unhandled user code hresult=-2146233087 message=an unknown error has occurred. error: 80020101. source=microsoft.phone.interop stacktrace: @ microsoft.phone.controls.nativemethods.validatehresult(int32 hr) @ microsoft.phone.controls.webbrowserinterop.invokescript(string scriptname, string[] args) @ microsoft.phone.controls.webbrowser.invokescript(string scriptname, string[] args) @ tabbed_browser.user_controls.webbrowser.attachcontextmenu() @ tabbed_browser.user_controls.webbrowser.webbrowser_loaded(object sender, routedeventargs e) @ ms.internal.coreinvokehandler.invokeeventhandler(int32 typeindex, delegate handlerdelegate, object sender, object args) @ ms.internal.jolthelper.fireevent(intptr unmanagedobj, intptr unmanagedobjargs, int32 argstypeindex, int32 actualargstypeindex, string eventname) innerexception: i've tried following, based on posting. apparently work in wp7 phone not in wp8 or emulator.
public void attachcontextmenu() { try { if (webbrowser.isscriptenabled) { webbrowser.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}"); webbrowser.invokescript("execscript", "document.oncontextmenu = handlecontextmenu;"); } } catch { } } i monitor result via scriptnotify never fired
private void webbrowser_scriptnotify(object sender, notifyeventargs e) { debug.writeline(e.value.tostring()); } anyone know how attach context menu in wp8 browser control?
edit
i've found info window.navigator.mspointerenabled false on webbrowser control , true on internet explorer application. mean can't implement touch event detection in control. can set enabled?
if window.navigator.mspointerenabled false ,you can use onmousedown , onmouseup monitor
Comments
Post a Comment