zoukankan      html  css  js  c++  java
  • 获取和设置WebBrowser内核IE版本

    static void SetWebBrowserFeatures(int ieVersion)
    {
        // don't change the registry if running in-proc inside Visual Studio
        if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
            return;
        //获取程序及名称
        var appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
        //得到浏览器的模式的值
        UInt32 ieMode = GeoEmulationModee(ieVersion);
        var featureControlRegKey = @"HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControl";
        //设置浏览器对应用程序(appName)以什么模式(ieMode)运行
        Registry.SetValue(featureControlRegKey + "FEATURE_BROWSER_EMULATION", appName, ieMode, RegistryValueKind.DWord);
        // enable the features which are "On" for the full Internet Explorer browser
        Registry.SetValue(featureControlRegKey + "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", appName, 1, RegistryValueKind.DWord);
    }
    
    static int GetBrowserVersion()
    {
        int browserVersion = 0;
        using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftInternet Explorer",
          RegistryKeyPermissionCheck.ReadSubTree,
          System.Security.AccessControl.RegistryRights.QueryValues))
        {
            var version = ieKey.GetValue("svcVersion");
            if (null == version)
            {
                version = ieKey.GetValue("Version");
                if (null == version)
                    throw new ApplicationException("Microsoft Internet Explorer is required!");
            }
            int.TryParse(version.ToString().Split('.')[0], out browserVersion);
        }
    
        if (browserVersion < 7)
        {
            throw new ApplicationException("Not Support");
        }
        return browserVersion;
    }
    
    static UInt32 GeoEmulationModee(int browserVersion)
    {
        UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode. 
        switch (browserVersion)
        {
            case 7:
                mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. 
                break;
            case 8:
                mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. 
                break;
            case 9:
                mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.                    
                break;
            case 10:
                mode = 10000; // Internet Explorer 10.
                break;
            case 11:
                mode = 11000; // Internet Explorer 11
                break;
        }
        return mode;
    }
    C#
    'set version
    'e.g. SetWebBrowserFeatures(6)
    Private Shared Sub SetWebBrowserFeatures(ByVal ieVersion As Integer)
        If LicenseManager.UsageMode <> LicenseUsageMode.Runtime Then Return
        'Get the program and name
        Dim appName = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
        'Get the value of the browser's mode
        Dim ieMode As UInt32 = GeoEmulationModee(ieVersion)
        Dim featureControlRegKey = "HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControl"
        'Set the browser to run the app (appName) in what mode (ieMode)
        Registry.SetValue(featureControlRegKey & "FEATURE_BROWSER_EMULATION", appName, ieMode, RegistryValueKind.DWord)
        'enable the features which are "On" for the full Internet Explorer browser
        Registry.SetValue(featureControlRegKey & "FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", appName, 1, RegistryValueKind.DWord)
    End Sub
    
    'get version
    Private Shared Function GetBrowserVersion() As Integer
        Dim browserVersion As Integer = 0
    
        Using ieKey = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftInternet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues)
            Dim version = ieKey.GetValue("svcVersion")
    
            If version Is Nothing Then
                version = ieKey.GetValue("Version")
                If version Is Nothing Then Throw New ApplicationException("Microsoft Internet Explorer is required!")
            End If
    
            Integer.TryParse(version.ToString().Split("."c)(0), browserVersion)
        End Using
    
        If browserVersion < 7 Then
            Throw New ApplicationException("Not Support!")
        End If
    
        Return browserVersion
    End Function
    
    Private Shared Function GeoEmulationModee(ByVal browserVersion As Integer) As UInt32
        Dim mode As UInt32 = 11000
    
        Select Case browserVersion
            Case 7
                mode = 7000
            Case 8
                mode = 8000
            Case 9
                mode = 9000
            Case 10
                mode = 10000
            Case 11
                mode = 11000
        End Select
    
        Return mode
    End Function
    VB.NET
  • 相关阅读:
    Post提交和Get提交的区别
    Servlet 生命周期
    MVC
    HDU 5033 Building (维护单调栈)
    2014 ACM/ICPC Asia Regional Xi'an Online(HDU 5007 ~ HDU 5017)
    HDU 1026 Ignatius and the Princess I (BFS)
    URAL 1183 Brackets Sequence(DP)
    POJ 3384 Feng Shui(半平面交向内推进求最远点对)
    POJ 3525 Most Distant Point from the Sea (半平面交向内推进+二分半径)
    POJ 1279 Art Gallery(半平面交求多边形核的面积)
  • 原文地址:https://www.cnblogs.com/jizhiqiliao/p/10207426.html
Copyright © 2011-2022 走看看