WebBrowser.ObjectForScripting プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > WebBrowser.ObjectForScripting プロパティの意味・解説 

WebBrowser.ObjectForScripting プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

WebBrowser コントロール表示される Web ページ内のスクリプト コードからアクセスできるオブジェクト取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Property ObjectForScripting As
 Object
Dim instance As WebBrowser
Dim value As Object

value = instance.ObjectForScripting

instance.ObjectForScripting = value
public Object ObjectForScripting { get; set;
 }
public:
property Object^ ObjectForScripting {
    Object^ get ();
    void set (Object^ value);
}
/** @property */
public Object get_ObjectForScripting ()

/** @property */
public void set_ObjectForScripting (Object
 value)
public function get ObjectForScripting
 () : Object

public function set ObjectForScripting
 (value : Object)

プロパティ
スクリプト コードから使用できるようにするオブジェクト

例外例外
例外種類条件

ArgumentException

このプロパティ設定時に指定された値が、パブリックではない型のインスタンスです。

または

このプロパティ設定時に指定された値が、COM 参照できない型のインスタンスです。詳細については、「Marshal.IsTypeVisibleFromCom」を参照してください

解説解説
使用例使用例

ObjectForScripting プロパティ使用する方法次のコード例示します。この例では、ObjectForScripting プロパティ現在のフォーム設定してます。

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
using System;
using System.Windows.Forms;
using System.Security.Permissions;

[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class Form1 : Form
{
    private WebBrowser webBrowser1 = new WebBrowser();
    private Button button1 = new Button();

    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }

    public Form1()
    {
        button1.Text = "call script code from client code";
        button1.Dock = DockStyle.Top;
        button1.Click += new EventHandler(button1_Click);
        webBrowser1.Dock = DockStyle.Fill;
        Controls.Add(webBrowser1);
        Controls.Add(button1);
        Load += new EventHandler(Form1_Load);
    }

    private void Form1_Load(object sender,
 EventArgs e)
    {
        webBrowser1.AllowWebBrowserDrop = false;
        webBrowser1.IsWebBrowserContextMenuEnabled = false;
        webBrowser1.WebBrowserShortcutsEnabled = false;
        webBrowser1.ObjectForScripting = this;
        // 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>";
    }

    public void Test(String message)
    {
        MessageBox.Show(message, "client code");
    }

    private void button1_Click(object sender,
 EventArgs e)
    {
        webBrowser1.Document.InvokeScript("test",
            new String[] { "called from client code"
 });
    }

}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からWebBrowser.ObjectForScripting プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からWebBrowser.ObjectForScripting プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からWebBrowser.ObjectForScripting プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

WebBrowser.ObjectForScripting プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebBrowser.ObjectForScripting プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS