利用webbrowser控件,如何破解内容不让复制的限制?

OnlyVB 2014-02-06 01:17:58

360doc右键不让复制内容,为啥下面的代码都不起作用呢,大家帮看看?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://www.360doc.com/content/12/1229/11/9200790_256942445.shtml")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.ScriptErrorsSuppressed = True
Dim doc As mshtml.IHTMLDocument2 = TryCast(WebBrowser1.Document.DomDocument, mshtml.IHTMLDocument2)
doc.parentWindow.execScript("document.oncontextmenu=new Function('event.returnValue=true;')", "javascript") '解除右键菜单限制
doc.parentWindow.execScript("document.onselectstart=new Function('event.returnValue=true;')", "javascript") '解除全选限制
doc.parentWindow.execScript("document.oncopy=new Function('event.returnValue=true;')", "javascript")
doc.parentWindow.execScript("document.onselect=new Function('event.returnValue=true;')", "javascript")
doc.parentWindow.execScript("document.onbeforecopy=new Function('event.returnValue=true;')", "javascript")
doc.parentWindow.execScript("document.onkeydown=Function('event.returnValue=true;')", "javascript") 'Ctrl+C可用
Dim elemlist As mshtml.IHTMLElementCollection = doc.getElementsByTagName("script")
'遍历JS操作
For Each elem As mshtml.IHTMLElement In elemlist
If elem.getAttribute("src") IsNot Nothing Then
elem.setAttribute("src", "#") '禁止js文件
End If
If elem.getAttribute("type") IsNot Nothing Then
elem.setAttribute("type", "text/vbscript") '修改脚本默认语言
End If
If elem.getAttribute("language") IsNot Nothing Then
elem.setAttribute("language", "vbscript") '修改脚本默认语言
End If
elem.outerHTML = "<script>return false;</script>" '修改js内容
Next
WebBrowser1.Document.Body.InnerHtml = Replace(WebBrowser1.Document.Body.InnerHtml, "document.write", "document..write", 1, -1, vbTextCompare) '禁止写入
WebBrowser1.Document.Body.InnerHtml = Replace(WebBrowser1.Document.Body.InnerHtml, "iframe", "iiframe", 1, -1, vbTextCompare) '禁止框架
'以上代码都不起作用
WebBrowser1.DocumentText = "<html><body>" & WebBrowser1.Document.Body.InnerHtml & "</body></html>" '该行起作用,但把页面破坏的面目全非
End Sub
...全文
183 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
OnlyVB 2014-02-06
  • 打赏
  • 举报
回复
哎,就想通过程序解决,基本可以了
rayyu1989 2014-02-06
  • 打赏
  • 举报
回复
360doc右键不让复制内容, 你为何不让浏览器禁用js
OnlyVB 2014-02-06
  • 打赏
  • 举报
回复
为啥需要用WebBrowser1.DocumentText 重写才起作用
WM_JAWIN 2014-02-06
  • 打赏
  • 举报
回复
把他放到黑名单。就这么简单

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧