我在同一页面中有2个浏览器。
当我点击并按住webBrowser2中的链接时,它会显示一个上下文菜单,代码为: XAML:
<toolkit:MenuItem Header="Open on Browser1" Click="open1" />
Xamls.cs:
public void AttachContextMenu()
{
try
{
if (webBrowser1.IsScriptEnabled)
{
webBrowser1.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}");
webBrowser1.InvokeScript("execScript", "document.oncontextmenu = HandleContextMenu;");
}
}
catch
{
}
}
现在我需要创建类似的东西:
private void open1(object sender, RoutedEventArgs e)
{
string xxx = *url taken from contextmenu*
webBrowser1.Navigate(new Uri(xxx, UriKind.Absolute));
}
我应该写什么代替 url取自contextmenu ?
谢谢!