[英]Disable hyperlink opening browser from c# winforms application
We have a .Net application that embeds google maps in some of the pages. 我们有一个.Net应用程序,它将Google地图嵌入到某些页面中。 We would like to prevent the user from opening a
WebBrowser
control when they click on a link found in Google Maps (such as in info tips on places etc...). 我们希望防止用户单击Google地图中的链接(例如在地方的信息提示等中)时打开
WebBrowser
控件。 Is this possible? 这可能吗? I'm fairly new to .Net :)
我对.Net还是相当陌生:)
尝试使用WebBrowser.AllowNavigation禁用导航
You can prevent navigations that are based on clicking a link using these 2 ways: 您可以使用以下两种方式来防止基于单击链接的导航:
1- Using AllowNavigation
property 1-使用
AllowNavigation
属性
this.webBrowser1.AllowNavigation = false;
2- Using Navigating
event 2-使用
Navigating
事件
private void BrowserSample_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.google.com");
this.webBrowser1.Navigating += webBrowser1_Navigating;
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
//you can use e.Url to allow or deny navigation based on your logic
e.Cancel = true;
}
Consider these notes when using one of the ways above: 使用上述方法之一时,请考虑以下注意事项:
Navigating
event you can gain more control over navigation and you can prevent some navigations and allow some others. Navigating
事件,您可以更好地控制导航,还可以阻止某些导航并允许其他一些导航。 Navigating
event, remember to add handler of this event only after you navigated to your desired url. Navigating
事件时,请记住仅在导航到所需的URL后才添加此事件的处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.