Doz*_*789 7 c# browser winforms
我有一个简单的程序,我正在尝试将kongregate聊天加载到一个WebBrowser,但它不起作用...
当我第一次启动时,它导航到一个游戏,然后它给了我4 Script Error,聊天就坐在那里说:"加入房间......".我不认为这是浏览器设置的问题,因为它适用于Internet Explorer.有什么东西搞砸了WebBrowser吗?我让它坐在那里几分钟,它仍然无法正常工作.我已将suppressScriptErrors设置为true和false,但仍然无法修复它.
供参考:我没有做什么坏事与我的程序,如欺骗,或发送垃圾邮件,或者类似的东西,我只是想在网页展现出来,有时候我希望能够有东西被复制,所以我把一些TextBoxes以它的权利,所以我可以将它粘贴到聊天中,如果我不发布一些东西......
dra*_*112 -1
这篇文章可以解决您的问题。Visual Studio 中的 WebBrowser 控件似乎默认以 IE7 模式启动。这就是为什么在控件中会出现 JavaScript 错误,但在浏览器中不会出现错误。我强烈建议您阅读顶部链接的文章。幸运的是,有一个修复方法。以下代码取自另一个 stackoverflow 答案,间接解决了您的问题。这是该链接,这是代码。
string installkey = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";
string entryLabel = Path.GetFileName(Application.ExecutablePath);
System.OperatingSystem osInfo = System.Environment.OSVersion;
string version = osInfo.Version.Major.ToString() + '.' + osInfo.Version.Minor.ToString();
uint editFlag = (uint)((version == "6.2") ? 0x2710 : 0x2328); // 6.2 = Windows 8 and therefore IE10
RegistryKey existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, false); // readonly key
if (existingSubKey == null) {
existingSubKey = Registry.LocalMachine.CreateSubKey(installkey, RegistryKeyPermissionCheck.Default); // readonly key
}
if (existingSubKey.GetValue(entryLabel) == null) {
existingSubKey = Registry.LocalMachine.OpenSubKey(installkey, true); // writable key
existingSubKey.SetValue(entryLabel, unchecked((int)editFlag), RegistryValueKind.DWord);
}
Run Code Online (Sandbox Code Playgroud)
另外,我在上面提到的文章说,您也应该为应用程序的 VS 主机进程创建一个条目,否则它将无法在调试模式下工作。祝你好运,我希望这能解决你的问题!