Web浏览器控件的window.external始终为null

2 browser null nothing

Web浏览器的Window.External对象始终为null!

要重现在新winform上删除Web浏览器并键入:

Option Strict Off

Public Class Form1
    Private Sub Form1_Load()
        Handles MyBase.LoadMe.WebBrowser1.Document.Window.DomWindow.External.AddFavorite("http://www.google.com")
    End Sub
End Class
Run Code Online (Sandbox Code Playgroud)

确保转到"装配信息"对话框并选中"使装配COM可见".这是必要的.

我迷失了为什么使用COM可见程序集外部对象总是什么都没有.

Mat*_*ton 6

您是否已将ObjectForScripting属性设置为主机窗口?我认为你需要为window.external做到这一点.


小智 6

另外,确保您设置为ObjectForScripting的对象具有以下属性:

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
Run Code Online (Sandbox Code Playgroud)

没有它,window.external总是为null.