web浏览器内部框架在默认浏览器中打开 [英] webbrowser iframes open in default browser
问题描述
我已经得到了WebBrowser控件打开像这样在我的默认浏览器链接:
I've got the WebBrowser control to open links in my default browser like this:
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.ToString() != "about:blank")
{
e.Cancel = true;
System.Diagnostics.Process.Start(e.Url.ToString());
}
}
这个伟大的工程,但如果我加载一个包含某些元素IFrame的那些将在系统浏览器中打开,以及(主要是嵌入式的东西,如谷歌地图,Digg的图标等)。
This works great but if I load a document that contains some IFrame elements those will be opened in the system browser as well (mostly embedded stuff, like Google Maps, Digg icons, etc..).
如何保持内部框架WebBrowser控件加载和用户点击在系统浏览器链接?
How do I keep iframes loading in the Webbrowser control and user clicked links in the system browser?
推荐答案
我得出的结论是,.NET WebBrowser组件是在这方面几乎无用。我试着读 WebBrowserNavigatingEventArgs.TargetFrameName
,但它会返回iframe元素只有在HTML的名称
属性文件有它。否则,它会吐出一个空,
字符串。非框架链接返回null本来吨更加有用。
I've come to the conclusion that the .NET WebBrowser component is almost useless in this regard. I've tried to read WebBrowserNavigatingEventArgs.TargetFrameName
but it will return the name
attribute of the iframe element only if the HTML document has it. Otherwise it will spit out an empty ""
string. Returning null on non-frame links would have been tons more useful.
所以,我发现这样做的唯一的解决方法是使用AxWebBrowser控制,并专门听取了BeforeNavigate2事件。我没有测试过,就像我应该有,但现在看来,在 DWebBrowserEvents2_BeforeNavigate2Event
设置为 64 每一次的标志属性是用户触发。
So the only fix I've found for this is using the AxWebBrowser control, and specifically listening to the BeforeNavigate2 event. I haven't tested as much as I should have, but it appears that the "flags" property in DWebBrowserEvents2_BeforeNavigate2Event
is set to 64 each time it's user triggered.
private void axWebBrowser1_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e)
{
// 64 means user triggered
if ((int)e.flags == 64 && e.uRL.ToString() != "about:blank")
{
e.cancel = true;
System.Diagnostics.Process.Start(e.uRL.ToString());
}
}
MSDN文档说,标记
是IE7 +唯一的参数,所以我不知道对IE6的机器会发生什么......
MSDN docs says that flags
is an IE7+ only parameter, so I have no idea what happens on IE6 machines...
从.NET 使用Internet Explorer有关于AxWebBrowser一些真正有价值的信息。
Using Internet Explorer from .NET has some really valuable information regarding AxWebBrowser.
这篇关于web浏览器内部框架在默认浏览器中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!