惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - 上午的绝缘杯

金斗云提醒用法说明 金斗云提醒软件的原理 向大家推荐一个谷歌浏览器笑话插件:一日一笑 企业知识管理专家:KMaster知识管理平台简介 KMaster知识管理平台功能简介 知识库如何跟其他业务系统结合 知识管理系统中的知识门户 KMaster知识库的特色功能 当前知识管理系统的焦点问题以及我的一些解决办法 企业级知识库系统KMaster推荐 ie6下的location.href错误 - 上午的绝缘杯 - 博客园 jQuery高亮插件 使用 .NET 实现 Ajax 长连接 (Part 2 - Mutex Wait & Signal) 利用Jquery实现http长连接(LongPoll) - 上午的绝缘杯 - 博客园 使用 .NET 实现 Ajax 长连接 (Part 1 - Comet Web Service) Comet:基于 HTTP 长连接的“服务器推”技术 非常好的进度条生成网站 火车票刷票器 学习lucene.net的好网站(不断添加)
webbrowser使用心得
上午的绝缘杯 · 2012-05-22 · via 博客园 - 上午的绝缘杯

最近用webbrowser做了个东西,期间有点小曲折,而且网上的解决方法也基本都是浅尝辄止,特此在这里发一下同大家分享。

1.首先是屏蔽浏览器右键菜单的问题,
用以下代码可以让浏览器用自己的右键菜单:
tempBrowser.ContextMenuStrip = this.contextMenuStrip1;
tempBrowser.IsWebBrowserContextMenuEnabled = false;

但是很不幸,上面的代码在有的机器上不起作用,开始以为是环境或者流氓插件的问题,折磨了很久无果,后来把.net升级到4.0竟然解决了这个问题,估计就是微软webbrowser控件的问题

2.屏蔽拷贝快捷键和截屏快捷键

        public bool PreFilterMessage(ref Message msg)
        {
            if (msg.Msg == WM_KEYDOWN || msg.Msg == WM_KEYUP)
            {
                StringBuilder sb = new StringBuilder(50);
                GetClassName(msg.HWnd, sb, 50);

                if (sb.ToString().ToLower() == "internet explorer_server")
                {
                    if ((Control.ModifierKeys == Keys.Control && (((Keys)msg.WParam.ToInt32() & Keys.KeyCode) == Keys.C)) || ((Keys)msg.WParam.ToInt32() & Keys.KeyCode) == Keys.PrintScreen || ((Keys)msg.WParam.ToInt32() & Keys.KeyCode) == Keys.Menu)
                    {
                        MessageBox.Show("当前系统禁止内容复制,如需系统内部复制粘贴,请使用右键菜单的功能!", "屏蔽");
                        Clipboard.SetDataObject("null");
                        return true;
                    }
                }
            }

            return false;
        }

3.解决webbrowser遇到window.open无法打开页面的问题
是因为打开页面的url一般是通过myBrowser.StatusText来获取的,但是window.open是无法获取真正的url的,解决办法就是在webbrowser的NewWindow事件中特殊处理window.open的事件,获取真正的url地址
            WebBrowser myBrowser = (WebBrowser)sender;
            TabPage mypage = (TabPage)myBrowser.Parent;
            string NewURL = "";
            string html = myBrowser.Document.ActiveElement.OuterHtml;
            string pattern = @"<button.*?onclick=.*\('(.*)'\).*";
            MatchCollection matches = Regex.Matches(html, pattern, RegexOptions.IgnoreCase);
            if (matches.Count == 1)
            {
                Match m = matches[0];
                Group g = m.Groups[1];
                if (g != null && g.Length > 0)
                {
                    string address = myBrowser.Url.Scheme + "://" + myBrowser.Url.Host + ":" + myBrowser.Url.Port + g.ToString();
                    NewURL = address.Replace("&amp;", "&");
                }
            }
            NewURL = string.IsNullOrEmpty(NewURL) ? myBrowser.StatusText : NewURL;


很遗憾这种方法只能适合一页中只有一个window.open的情况,如果有多个window.open,我们可以用下面的方法:在webbrowser的DocumentCompleted中,if (mybrowser.DocumentText.IndexOf("window.open(") > -1),然后把所有window.open替换为window.location.href。但是后来发现系统执行过这个过程之后,webbrowser的url会变成原来的url,不知道有没有朋友能知道为什么。

4.屏蔽webbrowser拖拽网页内容到外部word等的问题
        private void tempBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowser tempBrowser = (WebBrowser)sender;
            tempBrowser.Parent.Text = tempBrowser.DocumentTitle;
            HtmlElement ele = tempBrowser.Document.CreateElement("script");//新增
            ele.SetAttribute("type", "text/javascript");
            ele.SetAttribute("text", "document.body.ondragstart=function(){window.event.returnValue=false;};");
            tempBrowser.Document.Body.AppendChild(ele);
 }

还有几个参考网站送给大家做参考:

http://www.codeproject.com/Articles/13598/Extended-NET-2-0-WebBrowser-Control

http://www.cnblogs.com/chenou/articles/1163779.html

http://www.cnblogs.com/dlwang2002/archive/2007/04/14/713499.html