以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  如何判断网页加载完毕?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=147559)

--  作者:shanshuizhujian
--  发布时间:2020/3/19 12:19:00
--  如何判断网页加载完毕?
Dim WebBrowser1 As WinForm.WebBrowser
WebBrowser1 =  e.Form.CreateControl("WebBrowser1", ControlTypeEnum.WebBrowser)
WebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill
Dim webBrowser As Object = WebBrowser1.basecontrol
webBrowser.Url = new System.Uri(ProjectPath & "kindeditor\\index.html", System.UriKind.Absolute)
s="nihao"
\'msgbox(s)//这里不添加显示框,下面的一句代码就不起作用。为什么?
WebBrowser.Document.InvokeScript("setcontent", New String() {s})


我在网上找了一个判断网页加载完毕的代码,但不知道如何改写。
  1. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,URL As Variant)  
  2.    If (pDisp Is WebBrowser1.Object) Then  
  3.       Debug.Print "Web document is finished downloading"  
  4.    End If  
  5. End Sub  

--  作者:有点蓝
--  发布时间:2020/3/19 13:37:00
--  


--  作者:shanshuizhujian
--  发布时间:2020/3/19 15:38:00
--  回复:(有点蓝)参考:http://www.foxtable.com/bbs/...
还是不行,是不是我问的方向不对,我是想在网页加载后,用窗体命令执行网页里的一个js函数。
这句把网页编辑器加载后
web.Url = new System.Uri(ProjectPath & "kindeditor\\index.html", System.UriKind.Absolute)
\'msgbox("hh")
s="nihao"
\'msgbox(s)
执行下面这句话,把需要编辑的内容也加载进来。
web.Document.InvokeScript("setcontent", New String() {s})

现在的情况是,我不写msgbox这个对话框,下面的数据加载不进来,主要写上这一句,下面的这句话就可以加载进来数据。不写加载不进来。按照你给的地址我写了个判断函数,判断也是加载完毕了,但是还是不执行下面的函数。

vb.net里也不行
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        WebBrowser1.AllowWebBrowserDrop = False
        WebBrowser1.IsWebBrowserContextMenuEnabled = False
        WebBrowser1.WebBrowserShortcutsEnabled = False
        WebBrowser1.ObjectForScripting = Me
        WebBrowser1.Navigate("C:\\Users\\lenovo\\source\\repos\\编辑器\\index.html")
        Dim s As String = "hello"
        WebBrowser1.Document.InvokeScript("setcontent", New String() {s})//这句话是不起作用的。
    End Sub
[此贴子已经被作者于2020/3/19 15:42:29编辑过]

--  作者:有点蓝
--  发布时间:2020/3/19 15:46:00
--  
如果使用浏览器控件,需要看到网页的,请参考2楼第一个链接的实例,需要在全局代码添加一个事件,然后浏览器控件绑定到这个事件。然后其它操作都需要到全局代码里处理。

如果不需要看到网页的,参考第二个链接的用法
Dim web As New System.Windows.Forms.WebBrowser()
web.ScriptErrorsSuppressed = True
web.Navigate(ProjectPath & "kindeditor\\index.html")
Do Until web.ReadyState = 4 \'等待网页加载完毕
    Application.DoEvents
Loop
web.Document.InvokeScript("setcontent", New String() {s})

--  作者:shanshuizhujian
--  发布时间:2020/3/19 16:02:00
--  回复:(有点蓝)如果使用浏览器控件,需要看到网页的...
"然后其它操作都需要到全局代码里处理。"
这句话很关键,我没有把处理代码写到全局里,我尝试一下,谢谢这么迅速回答。