admin管理员组文章数量:1315998
Ok, I have a very frustrating problem. I am parsing a webpage and need to have it execute the javascript in order to get the information I want.
Form f = new Form();
WebBrowser w = new WebBrowser();
w.Navigate(url);
f.Controls.Add(w);
f.ShowDialog();
HtmlElementCollection hc = w.Document.GetElementsByTagName("button");
This works and I'm able to get the button elements fine, but then I get a popup everytime I run this. Very annoying. The popup is javascript based and I need to run Javascript to get the button element info. Here is the script for the popup.
<script>
var evilPopup = (getCookieVar("markOpen","PromoPop") == 1);
if (evilPopup != 1)
{
PromoPop = window.open('/browse/info.aspx?cid=36193','Advertisement', 'width=365,height=262,screenX=100,screenY=100');
if (PromoPop)
{
PromoPop.blur();
window.focus();
setCookieVar("markOpen","PromoPop","1");
}
}
</script>
I tried in vane to possibly add a cookie to the Forms.Webbrowser control but got frustrated and gave up. I tried setting the NoAllowNavagate property and everything else to no avail.
Can anyone help? Also, there a way to get the DomDocument info from the Console.App without having to open a form?
Thanks
Ok, I have a very frustrating problem. I am parsing a webpage and need to have it execute the javascript in order to get the information I want.
Form f = new Form();
WebBrowser w = new WebBrowser();
w.Navigate(url);
f.Controls.Add(w);
f.ShowDialog();
HtmlElementCollection hc = w.Document.GetElementsByTagName("button");
This works and I'm able to get the button elements fine, but then I get a popup everytime I run this. Very annoying. The popup is javascript based and I need to run Javascript to get the button element info. Here is the script for the popup.
<script>
var evilPopup = (getCookieVar("markOpen","PromoPop") == 1);
if (evilPopup != 1)
{
PromoPop = window.open('/browse/info.aspx?cid=36193','Advertisement', 'width=365,height=262,screenX=100,screenY=100');
if (PromoPop)
{
PromoPop.blur();
window.focus();
setCookieVar("markOpen","PromoPop","1");
}
}
</script>
I tried in vane to possibly add a cookie to the Forms.Webbrowser control but got frustrated and gave up. I tried setting the NoAllowNavagate property and everything else to no avail.
Can anyone help? Also, there a way to get the DomDocument info from the Console.App without having to open a form?
Thanks
Share Improve this question edited Apr 25, 2009 at 18:59 IAdapter 64.9k73 gold badges186 silver badges243 bronze badges asked Apr 25, 2009 at 18:35 ErdnodErdnod4 Answers
Reset to default 6The WebBrowser ponent has NewWindow event with CancelEventArgs. So just add a handler similar to:
void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true;
}
When the javascript tries to open a popup window the event gets triggered and cancels it.
Can you inject Javascript into the document? You could add this:
window.open = function() { return false; }
A quick and dirty solution would be to use WebClient to download the html to a temporary file, replace the ad script with string.Empty and load the file in the control.
you should try SHDocVw.dll to automatically catch new window.
private SHDocVw.WebBrowser_V1 Web_V1;
// write it on form load event
Web_V1 = (SHDocVw.WebBrowser_V1)this.webBrowser1.ActiveXInstance;
Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(Web_V1_NewWindow);
private void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed)
{
Processed = true; //Stop event from being processed
//Code to open in same window
//this.webBrowser1.Navigate(URL);
//Code to open in new window instead of same window
frmEBeyanname Popup = new frmEBeyanname();
Popup.webBrowser1.Navigate(URL);
Popup.Show();
}
bye
本文标签: netDisable Javascript popups when using WindowsFormsWebbrowserNavigate()Stack Overflow
版权声明:本文标题:.net - Disable Javascript popups when using Windows.Forms.Webbrowser.Navigate() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741993513a2409580.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论