如下面一个最简单的代码怎样,不通过在本地存文件通过navigate方法实现,
应用背景是,我要把Webbrowser1中显示的内容传到Webbrowser2上显示(然后进行相应的操作),如果用通过保存文件,然后用navigate方法,有些网页使用了脚本,相对超连接地址,这种方法就会有问题。<html>
<head><title>hi</title></head>
<body >hi</body>
</html>

解决方案 »

  1.   

    document 的write方法不知在什么时候可以用,我试了不行
    另外不能往html标签中改变innerHtml 或者 outerHtml属性的值
    高手出招,又没有解决办法阿,在线等待
      

  2.   

    我按下这个帖子,用 liuxiaoyi666的方法,写不进去东西,为何
    http://topic.csdn.net/topicfiles/2005/05/06/16/3985892.xmlweb.Navigate "about: blank"        '设置空白页
        
        web.Document.Open                  '写入当前可编辑内容
        web.Document.write "<HTML><HEAD><TITLE>ZCM's PRM</TITLE></HEAD><BODY STYLE='overflow:hidden; margin:0px'></BODY></HTML>"
        
        Set sPara = web.Document
        Set nPara = sPara.getElementById("dlgHelper")    '调用dlghelper对象这个是当然的了,你的object还没加载呢,哪找id给你调用的
      

  3.   

    只有在浏览器控件自身触发Documentcomplete事件之后DHTML文档对象模型才可以访问
    1 用CreateElement来创建,之后用appendchild等方法添加到文档
    2 你可以用文档的IPersistStreamInit接口来完全替换文档中的内容
      

  4.   

    'This is short code that will add a javascript to a webpage as it loads in your browser
    ' In this particular example my script adds a javascript that will send the value of tagVars variable to the clibboard and then 
    'have a textbox(make sure its multiline) get the data from the clipboard'all code goes in the webbrowser1_DocumentComplete event
    Private Sub webbrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)'Just avioding errors
    On Error Resume Next'Clear the textbox and clipboard.
        txtData.Text = ""
        Clipboard.Clear
        WebBrowser1.Document.expando = True ' Not sure if required but can't hurt' The following line add a link to the page that when clicked, runs a javascript from its href
        WebBrowser1.Document.body.insertBefore (WebBrowser1.Document.createElement("<a name=""see"" href=""javascript:if(typeof(tagVars)!='undefined') var sucsess = window.clipboardData.setData('Text',tagVars);"" >test2</a>"))' This line clicks the link and runs the javascript
        WebBrowser1.Document.links(WebBrowser1.Document.links.length - 1).Click
    'This loops makes sure the javascript has run before proceeding
        Do
              DoEvents
        Loop While WebBrowser1.Busy
     
    ' Set focus to the text box and then paste
        txtData.SetFocus
        txtData.SelText = Clipboard.GetText(vbCFText)
    End Sub'Note adding the javascript is tricky and you may have to view the output of createElement in the debuger to see where it 
    'goes wrong
      

  5.   

    Dim webdoc As HTMLDocument
    Dim texbody As HTMLBody
    Dim Rng As IHTMLTxtRangePrivate Sub Command1_Click()
    Set Rng = texbody.createTextRange()
    Rng.pasteHTML "<h1>测试</h1>"
    End SubPrivate Sub Command2_Click()
    On Error Resume Next
    Set Rng = texbody.createTextRange()
    Clipboard.Clear
    Clipboard.SetText Rng.Text
    End SubPrivate Sub Form_Load()
    WebBrowser1.Navigate App.Path & "\1.htm"
    End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Set webdoc = WebBrowser1.Document
    Set texbody = webdoc.body
    'Set Rng = texbody.createTextRange()
    Command1.Enabled = True
    Command2.Enabled = True
    End Subhttp://club.5ivb.net/dispbbs.asp?BoardID=123&replyID=61065&id=44375&star=1&skin=0http://club.5ivb.net/dispbbs.asp?BoardID=123&replyID=62782&id=44766&star=1&skin=0