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. not 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. On WP8, I did it using the onmousedown event, a timer and the onmouseout event in combination with the findparentlink function from WP7.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.