简体   繁体   中英

Webbrowser Control how to change a window javascript property?

I need to change the User-Agent of my webbrowser control. But no using the overload of the Navigating method ( because the script get the user agent not from the header, but from the window.navigator.appName property. Is there a way to change this property in the webbrowser??

Thanks!

update: window.navigator should be a property you can overwrite via IDispatchEx (IExpando on the CLR runtime wrapper) in Javascript. something like

var document=webBrowser1.Document.DomDocument as MSHTML.IHTMLDocument2;
var expando =(IExpando)document.parentWindow;
expando.RemoveProperty(expando.GetMember("navigator",BindingFlags.Instance | BindingFlags.Public));
expando.AddProperty("navigator").SetValue(expando,myNavigator);

here myNavigator is a variable of a COM visible type that has an appName property.

not working: pinvoke UrlMkSetSessionOption and pass URLMON_OPTION_USERAGENT as the option flag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM