動(dòng)態(tài)改變webbrowser的內(nèi)容,斷行的字無法改變,功能無
下面可以動(dòng)態(tài)改變webbrowser的內(nèi)容
1.處理方式一產(chǎn)生的問題
如果字串有斷行就無法修改了例如
"我的書
集收藏"
""<-- 內(nèi)的是一整句
2.處理方式二產(chǎn)生的問題
執(zhí)行後可以取代所有文字含連結(jié)也可以修改
但 原來的 js 或者是 script 的一部分功能無法使用了
請(qǐng)問有高手知道我的問題要如解決嗎?
還是我方法錯(cuò)了可以指導(dǎo)我一下嗎?
'程式碼
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.WebBrowser1.Url = New System.Uri("http://www.csdn.net", System.UriKind.Absolute)
End Sub
處理方式一:
Private Sub WebCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
test()
End Sub
Private Sub test()
Dim htmlDoc As HtmlDocument = WebBrowser1.Document
'遍曆HtmlElement對(duì)象
For Each htmlEle As HtmlElement In htmlDoc.All
With htmlEle
Try
'檢查目前元素的純文字
Select Case .OuterText
Case "我的簡(jiǎn)曆"
'根據(jù)需要取代掉
.OuterHtml = .OuterHtml.Replace("我", "你")
Case "我的帖子"
.OuterHtml = .OuterHtml.Replace("我", "你")
Case "我的Blog"
.OuterHtml = .OuterHtml.Replace("我", "你")
Case "我的網(wǎng)摘"
.OuterHtml = .OuterHtml.Replace("我", "你")
Case "我的書架"
.OuterHtml = .OuterHtml.Replace("我", "你")
Case "我的資源"
.OuterHtml = .OuterHtml.Replace("我", "你")
Case Else
End Select
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
Next
End Sub
處理方式二:
Private Sub WebCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
test()
End Sub
Private Sub test()
Dim htmlDoc As HtmlDocument = WebBrowser1.Document
'遍曆HtmlElement對(duì)象
For Each htmlEle As HtmlElement In htmlDoc.All
With htmlEle
Try
'檢查目前元素的純文字
strHtml = .OuterHtml
intWord = -1
Do While intWord <= UBound("目標(biāo)文字陣列")
intWord += 1
strHtml = strHtml.Replace("目標(biāo)文字","取代文字")
Loop
.OuterHtml = strHtml
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
Next
End Sub
不好意思
這個(gè)問題己經(jīng)處理了
方法是過瀘掉 js 就可以了 ^^"
該評(píng)論在 2013/11/19 9:15:06 編輯過