2013-03-27 76 views
2

我在我的VBForm中有一個webbrowser控件。 它在我的網站上尋找一個網站並顯示它。VB.NET WebBrowser控件 - 你如何提交給默認瀏覽器?

WebBrowser1中有表單提交按鈕。 我希望它是這樣的,當他們點擊WebBrowser1網頁上的一個按鈕時,它會打開他們自己的瀏覽器來提交表格

我該怎麼做?

(是的,這是我的網站,如果需要我可以改變服務器上的HTML。)

+0

http://stackoverflow.com/questions/1562183/opening-default-web-browser – 2013-03-27 09:00:40

+0

的潛在副本沒有。我期待在VB瀏覽器控件中創建一個LINK來打開他們的瀏覽器來執行提交。而不是如何從子或功能打開他們的瀏覽器。 – WaxyChicken 2013-03-27 09:18:47

+0

但是如果你能告訴我如何使System.Windows.Forms.WebBrowser中的SUBMIT BUTTON調用一個子然後打開他們的瀏覽器來提交表單,那麼我可以使用它。 – WaxyChicken 2013-03-27 09:27:58

回答

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 

如果馬丁帕金沒有發佈重複警告,我永遠不會解決它。

也必須改變我的鏈接到METHOD = GET,帖子標題並不總是以這種方式翻譯。

+0

你可以接受你自己的答案。 – 2013-03-27 22:56:03