2017-11-03 1 views
0

こんにちは私は「なぜあなたは気になるでしょうか」という質問をしていますが、ビルドしようとしている私のアプリの重要な点です(これは短い話です)。2つのWebブラウザ間の相互作用

私のアプリは2つのサイド・バイ・サイド・ウェブ・ブラウザで構成され、1つのトリガー(例えばボタン)で構成され、2つ目のアクション(アラート・ポップアップ)は、 vb.netの言語ですか?

+0

をやり取りする方法を示しobjectforsciptingにMSDNから逮捕いくつかのサンプルコードである私はあなたの最善の策は、その後、プログラムで、最初のブラウザからクリックイベントを捕捉することだと思います2番目に何かを誘発する。 [this](https://stackoverflow.com/a/20921284)と[this](https://stackoverflow.com/a/14934426)を参照してください。 –

答えて

0

これは、がホストしているコンテンツを制御していると仮定すると、限定的に可能です

ObjectForScriptingプロパティでは、javascriptから.netにデータを渡して、もう一度1つのWebブラウザが他のブラウザに反応できるようにすることをお勧めします。

良いニュースのもう1つのビットは、同じWinInetキャッシュを使用することです。したがって、サイトのCookieを作成した場合、セッションCookieなどの場合、両方のブラウザでそのCookieを読み取る可能性があります。

私はあなたにあなたのより良い、より詳細な答えを与えるために念頭に置いていたことについてもう少し知る必要があります。ここで

は、単一のWebブラウザコントロールで

Imports System 
    Imports System.Windows.Forms 
    Imports System.Security.Permissions 

    <PermissionSet(SecurityAction.Demand, Name:="FullTrust")> 
    <System.Runtime.InteropServices.ComVisibleAttribute(True)> 
    Public Class Form1 
     Inherits Form 

     Private webBrowser1 As New WebBrowser() 
     Private WithEvents button1 As New Button() 

     <STAThread()> 
     Public Shared Sub Main() 
      Application.EnableVisualStyles() 
      Application.Run(New Form1()) 
     End Sub 

     Public Sub New() 
      button1.Text = "call script code from client code" 
      button1.Dock = DockStyle.Top 
      webBrowser1.Dock = DockStyle.Fill 
      Controls.Add(webBrowser1) 
      Controls.Add(button1) 
     End Sub 

     Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _ 
      Handles Me.Load 

      webBrowser1.AllowWebBrowserDrop = False 
      webBrowser1.IsWebBrowserContextMenuEnabled = False 
      webBrowser1.WebBrowserShortcutsEnabled = False 
      webBrowser1.ObjectForScripting = Me 
      ' Uncomment the following line when you are finished debugging. 
      'webBrowser1.ScriptErrorsSuppressed = True 

      webBrowser1.DocumentText = 
       "<html><head><script>" & 
       "function test(message) { alert(message); }" & 
       "</script></head><body><button " & 
       "onclick=""window.external.Test('called from script code')"" > " & 
       "call client code from script code</button>" & 
       "</body></html>" 
     End Sub 

     Public Sub Test(ByVal message As String) 
      MessageBox.Show(message, "client code") 
     End Sub 

     Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _ 
      Handles button1.Click 

      webBrowser1.Document.InvokeScript("test", 
       New String() {"called from client code"}) 

     End Sub 

    End Class 
関連する問題