积极答复者
在webBrowser1中点击链接,如何限制他只在webBrowser中打开

问题
答案
-
你好,
你可以将链接的target="_blank"改为target="self ",并使用e.Cancel=true,取消息打开新窗口动作。
如:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //将所有的链接的目标,指向本窗体 foreach (HtmlElement archor in this.webBrowser1.Document.Links) { archor.SetAttribute("target", "_self"); } //将所有的FORM的提交目标,指向本窗体 foreach (HtmlElement form in this.webBrowser1.Document.Forms) { form.SetAttribute("target", "_self"); } } private void webBrowser1_NewWindow(object sender, CancelEventArgs e) { e.Cancel = true; }
请参考以下链接:
http://www.cnblogs.com/hfzsjz/archive/2012/11/21/2780169.html
http://blog.csdn.net/maji9370/article/details/4938865
希望对你有所帮助。
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 lkf18 2012年12月25日 11:08
全部回复
-
你好,
你可以将链接的target="_blank"改为target="self ",并使用e.Cancel=true,取消息打开新窗口动作。
如:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //将所有的链接的目标,指向本窗体 foreach (HtmlElement archor in this.webBrowser1.Document.Links) { archor.SetAttribute("target", "_self"); } //将所有的FORM的提交目标,指向本窗体 foreach (HtmlElement form in this.webBrowser1.Document.Forms) { form.SetAttribute("target", "_self"); } } private void webBrowser1_NewWindow(object sender, CancelEventArgs e) { e.Cancel = true; }
请参考以下链接:
http://www.cnblogs.com/hfzsjz/archive/2012/11/21/2780169.html
http://blog.csdn.net/maji9370/article/details/4938865
希望对你有所帮助。
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 lkf18 2012年12月25日 11:08
-