我的VBForm中有一个webbrowser控件。 它在我的网站上查找并显示它。
WebBrowser1中有表单提交按钮。 我希望它是这样的,当他们点击WebBrowser1网页上的一个按钮时,它将打开自己的浏览器来提交表单
我该怎么做?
(是的,这是我的网站。如果需要,我可以更改服务器上的HTML。)
答案 0 :(得分:1)
答案归功于:Opening default web browser 并且:vb.net WebBrowser links to Default Web Browser
和一些反复试验。工作结果如下:
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
'added a match string - if Allow is inside the URL link, then the WebBrowser control is allowed to navigate to it. otherwise use their browser.
dim Allow as string = "http://mysite.com"
If InStr(e.Url.ToString(), Allow) = 0 Then
' I'm trying here to cancel the event so that the WebBrowser1 control doesn't go there.
e.Cancel = True
' then start a new process with their default browser
System.Diagnostics.Process.Start(getDefaultBrowser(), e.Url.ToString())
End If
End Sub
Private Function getDefaultBrowser() As String
Dim browser As String = String.Empty
Dim key As RegistryKey = Nothing
Try
key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
'trim off quotes
browser = key.GetValue(Nothing).ToString().ToLower().Replace("""", "")
If Not browser.EndsWith("exe") Then
'get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
End If
Finally
If key IsNot Nothing Then
key.Close()
End If
End Try
Return browser
End Function
如果Martin Parkin没有发布重复警告,我永远不会解决它。
还 - 必须更改我的METHOD = GET链接,帖子标题并不总是以这种方式翻译。