c# - How to add a context menu in the webbrowser? -
i know there thread relating this, need more information. @ moment, have code got form other thread,
public void attachcontextmenu() { try { if (webtab1.isscriptenabled) { webtab1.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}"); webtab1.invokescript("execscript", "document.oncontextmenu = handlecontextmenu;"); } } catch { } }
the thread said when browser has finished loading call method, although doesnt seem work.
any ideas on how can work?
this works on windows phone 7.x only. not 8.
addhandler wb.loaded, sub(sendr object, ev eventargs) wb.isscriptenabled = true attachcontextmenu() end sub addhandler wb.scriptnotify, sub(sender object, e microsoft.phone.controls.notifyeventargs) diagnostics.debug.writeline(e.value.tostring) end sub
if know how open context menu in wp8 webbrowser control, please let know. on wp8, did using onmousedown event, timer , onmouseout event in combination findparentlink function wp7.
Comments
Post a Comment