c# - Webbrowser dialog popup block -


i developing program has invisible web browser control used loading data web pages. however, having trouble blocking type of popup.

this code using block popups

private void webbrowser1_newwindow( object sender,                                      system.componentmodel.canceleventargs e) {   e.cancel = true; } 

i have tested on http://www.popuptest.com/ , fails block come & go test , modeless window test. http://i75.servimg.com/u/f75/13/13/40/49/b11.png

is there way block these popups?

this javascript shows popups

function modelesswin(url,mwidth,mheight){ if (document.all&&window.print) //if ie5     eval('window.showmodelessdialog(url,"","help:0;resizable:1;dialogwidth:'+mwidth+'px;dialogheight:'+mheight+'px")') else eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")') }   modelesswin("http://www.popuptest.com/popup1.html",600,600) 

try implementing webbrowser feature control, particularly feature_block_input_prompts , feature_weboc_popupmanagement.

[edited] code works me test site, try (tested ie10). make sure set features before webbrowser gets created (before initializecomponent below) , scripterrorssuppressed = true suppress script errors caused blocked pop-ups.

using system; using system.runtime.interopservices; using system.windows.forms; using system.diagnostics; using microsoft.win32;  namespace winformswb {     public partial class form1 : form     {          public form1()         {             setbrowserfeaturecontrol();             initializecomponent();         }          private void form1_load(object sender, eventargs e)         {             this.webbrowser1.scripterrorssuppressed = true;             this.webbrowser1.navigate("http://www.popuptest.com/");         }          private void setbrowserfeaturecontrolkey(string feature, string appname, uint value)         {             using (var key = registry.currentuser.createsubkey(                 string.concat(@"software\microsoft\internet explorer\main\featurecontrol\", feature),                 registrykeypermissioncheck.readwritesubtree))             {                 key.setvalue(appname, (uint32)value, registryvaluekind.dword);             }         }          private void setbrowserfeaturecontrol()         {             // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx              // featurecontrol settings per-process             var filename = system.io.path.getfilename(process.getcurrentprocess().mainmodule.filename);              // make control not running inside visual studio designer             if (string.compare(filename, "devenv.exe", true) == 0 || string.compare(filename, "xdesproc.exe", true) == 0)                 return;              // todo: feature_browser_mode - it?             setbrowserfeaturecontrolkey("feature_browser_emulation", filename, 9000); // webpages containing standards-based !doctype directives displayed in ie10 standards mode.             setbrowserfeaturecontrolkey("feature_disable_navigation_sounds", filename, 1);             setbrowserfeaturecontrolkey("feature_weboc_popupmanagement", filename, 1);             setbrowserfeaturecontrolkey("feature_block_input_prompts", filename, 1);         }     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -