1、我想用Inet控件获取某网页的HTML代码然后用"WebBrowser1.Document.Write sHTML"的方法写入WebBrowser控件中,但是由于取得的代码中大部分路径都是相对路径,用以上方法无法达到直接用"WebBrowser1.Navigate 网址"的效果,能否给WebBrowser控件设置一个"当前路径"?除了分析字符串把所有相对路径改成绝对路径外还有什么其他方法可以解决这个问题?2、在WebBrowser中点击一个类似这样的链接:
<a href="http://www.baidu.com" target="_blank">百度</a>
如何得到点击的链接地址是"http://www.baidu.com"?
<a href="http://www.baidu.com" target="_blank">百度</a>
如何得到点击的链接地址是"http://www.baidu.com"?
因为这个链接的target是新窗口,所以点击这个链接后只会发生newwindow2事件而不发生beforenavegate2事件,而newwindow2这个事件中并不提供点击的这个链接的任何信息。我曾试着把这个webbrowser控件的document定义为一个HTMLDocument,但是链接的拖动会触发HTMLDocument的ondragstart事件,链接的点击却不会触发HTMLDocument的onclick事件!继续请教!
*****************************************************************************
欢迎使用CSDN论坛阅读器 : CSDN Reader(附全部源代码)
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
因为这个链接的target是_blank,所以点击这个链接后只会发生newwindow2事件而不发生beforenavegate2事件
============================Option ExplicitPrivate mbInitialize As BooleanPrivate WithEvents moDocument As HTMLDocumentPrivate Sub Form_Load()
mbInitialize = False
WebBrowser1.Navigate "about:blank"
End SubPrivate Function moDocument_onclick() As Boolean
'键盘事件类此处理
If moDocument.elementFromPoint(moDocument.parentWindow.event.x, moDocument.parentWindow.event.y).tagName = "A" Then
Text1.Text = moDocument.elementFromPoint(moDocument.parentWindow.event.x, moDocument.parentWindow.event.y).href
moDocument_onclick = False
Else
moDocument_onclick = True
Text1.Text = ""
End If
End FunctionPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If mbInitialize = False Then
mbInitialize = True
Set moDocument = WebBrowser1.Document
moDocument.body.innerHTML = "<a href=""http://www.baidu.com"" target=""_blank"">百度</a>"
Else
End If
End Sub============================
你的工分可不大好挣啊, 接分, 哈哈
我的第2个问题已经被你给解决了,感谢,同时50分已经记在你的名上了,等另一个问题解决后一起结贴(最多3天后解决不了也会结贴)。
第1个问题应该也不很难,毕竟WebBrowser和Inet控件是共用同一个Session的。
是帮别人做的一个小项目 收费的第一个问题不太好弄 除非晓得webbrowns的内部规则 直接去修改它的内存去改写相对网页路径好了
但是第二个问题又出现了一点小的波折:我这个链接是在web_documentcomplete事件中改写了某个tag的innerhtml后添加上去的,比如有个<td>本来的innerhtml是"<td>内容</td>",我给它改成"<td>内容</td><a href=http://www.xxx.com target=_blank>test</a>",然后我"set objDoc=web.document",但是当点击这个新加上去的链接的时候,竟然不会触发objDoc_onclick事件,好像是objDoc还不承认这个新链接是自己的一部分,这又该怎么办呢?