现在的位置: 首页 > 综合 > 正文

VB调用webbrowser技巧集2

2012年06月10日 ⁄ 综合 ⁄ 共 578字 ⁄ 字号 评论关闭

向Webbrowser中写入HTML内容的几种方法

首先在Form_Load中加入

WebBrowser1.Navigate "about:blank"

确保Webbrowser1可用

 

方法1:

    Dim s As String
    Dim stream As IStream
      
    s = ""
    s = s + ""
    s = s + ""
    s = s + "

hello world

"
    s = s + ""
    s = s + "   
    WebBrowser1.Document.Write s

 

方法2:

    Dim o
  
    Set o = WebBrowser1.Document.selection.createrange
    Debug.Print o
    If (Not o Is Nothing) Then
        o.pasteHTML "哈哈"
        Set o = Nothing
    End If

 

方法3:

    '插入文本框
    Dim o

    Set o = WebBrowser1.Document.selection.createrange
   
    o.execCommand "InsertTextArea", False, "xxx"

 

其中方法3是采用了调用execCommand并且传递控制命令的方法,通过这种方法还可以插入图片等页面元素,详情可以参考MSDN的execCommand命令。

抱歉!评论已关闭.