Reputation: 139
I have a webbrowser control in my VBForm. It looks for a website on my site and displays it.
There are form submit buttons in that WebBrowser1. I would like it to be so that when they click a button in the WebBrowser1 Web page it will open their own browser to submit the form
How do i do this?
(yes, it's my website. i can change the HTML on the server if that is needed. )
Upvotes: 2
Views: 5265
Reputation: 139
answer is thanks to: Opening default web browser and: vb.net WebBrowser links to Default Web Browser
and some trial and error. working result follows:
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
I never would of solved it if Martin Parkin didn't post up that duplicate warning.
also - had to change my links to METHOD = GET, the post headers don't always translate in this manner.
Upvotes: 1