方法一
加入你想讓WebBrowser控件的渲染模式編程IE8的標准模式, 你可以通過設置注冊表FEATURE_BROWSER_EMULATION 來實現。
示例:
注冊表中注明當前本機裝的IE版本
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer
下面有名稱為Version的項,其值為IE的版本.
svcVersion =10.0.9200.16618
Version =9.10.9200.16618
[(HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE)\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"MyApplication.exe" = dword 8000 (Hex: 0x1F40)
這里MyApplicaiton.exe 是你的應用程序的EXE文件名。 8000 表示8.0的渲染模式,請對照下表:
IE8 Standards Mode 8000 (0x1F40) -- IE8 標准模式 (Standard Mode), IE8默認的模式
IE7 Standards Mode 7000 (0x1B58) -- IE7 兼容視圖模式 (Compatible View), IE8的WebBrowser控件默認模式
IE8 Standards Mode (Forced) 8888 (0x22B8) -- IE8 強制標准模式,在渲染失敗的情況下不嘗試用兼容視圖模式
方法二
在html頭 加標簽 強制使用最新的ie渲染 <meta http-equiv="X-UA-Compatible" content="IE=edge">
強制使用最新的ie8渲染<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>
修改案例:
void WINAPI WriteWebBrowserRegKey(LPCTSTR lpKey,DWORD dwValue) { HKEY hk; CString str = "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\"; str += lpKey; if (RegCreateKey(HKEY_LOCAL_MACHINE,str,&hk)!=0) { MessageBox(NULL,"打開注冊表失敗!","Error",0); ExitProcess(-1); } if (RegSetValueEx(hk,"你的exe名稱.exe",NULL,REG_DWORD,(const byte*)&dwValue,4)!=0) { RegCloseKey(hk); MessageBox(NULL,"寫注冊表失敗!","Error",0); ExitProcess(-1); } RegCloseKey(hk); }
WriteWebBrowserRegKey("FEATURE_BROWSER_EMULATION",9000); //WriteWebBrowserRegKey("FEATURE_ACTIVEX_REPURPOSEDETECTION",1); WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_IMG",1); WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_OBJECT",1); WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_SCRIPT",1); WriteWebBrowserRegKey("FEATURE_Cross_Domain_Redirect_Mitigation",1); WriteWebBrowserRegKey("FEATURE_ENABLE_SCRIPT_PASTE_URLACTION_IF_PROMPT",1); WriteWebBrowserRegKey("FEATURE_LOCALMACHINE_LOCKDOWN",1); WriteWebBrowserRegKey("FEATURE_GPU_RENDERING",1);