[英]How to add a context menu in the webbrowser?
I know there is already a thread relating to this, but i need more information. 我知道已经有一个与此相关的主题,但是我需要更多信息。 At the moment, i have this code which i got form the 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 that when the browser has finished loading you just call this method, although it doesnt seem to work. 该线程说,当浏览器完成加载后,您可以调用此方法,尽管它似乎不起作用。
Any Ideas on how i can get it to work? 关于如何使它工作的任何想法?
This works on Windows Phone 7.X only. 这仅适用于Windows Phone7.X。 not 8.
不是8。
AddHandler wb.Loaded, Sub(sendr As Object, ev As EventArgs)
wb.IsScriptEnabled = True
AttachContextMenu()
End Sub
AddHandler wb.ScriptNotify, Sub(sender As Object, e As Microsoft.Phone.Controls.NotifyEventArgs)
Diagnostics.Debug.WriteLine(e.Value.ToString)
End Sub
If you know how to open a context menu in WP8 WebBrowser control, please let us all know. 如果您知道如何在WP8 WebBrowser控件中打开上下文菜单,请告知我们。 On WP8, I did it using the onmousedown event, a timer and the onmouseout event in combination with the findparentlink function from WP7.
在WP8上,我将onmousedown事件,计时器和onmouseout事件与WP7中的findparentlink函数结合使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.