googleid_102416
12 years agoContributor
Changing Browser Mode of Internet Explorer
What is the best way to change Internet Explorer Browser Mode? I've posted my solution below but I don't like it because:
1) It will not work if you call switchIEBrowserMode while Developer Tool is already opened.
2) It seems to be locked to English locale.
3) page.Keys() posts warning when several tabs are opened because it sends key presses to background page.
4) Detection of toolbar is terrible.
Any ideas how to do this better?
function switchIEBrowserMode(browser_mode_id) {
var menu_items = {
"ie7": "Internet Explorer 7",
"ie8": "Internet Explorer 8",
"ie9": "Internet Explorer 9"
};
if(!browser_mode_id in menu_items)
return -1;
var browser = Sys.Browser("iexplore");
var page = browser.Page("*");
page.Keys("[F12]");
var toolbar = browser.BrowserWindow(0).Window("Frame Tab", "", 1).Tab("*").Window("BaseBar", "Horizontal Explorer Bar", 1).Window("ReBarWindow32", "", 1).Window("IEDEVTOOLS").Window("IEDEVTOOLSMENU").Window("ToolbarWindow32");
toolbar.ClickItem("&Browser Mode:*");
toolbar.PopupMenu.Click(menu_items[browser_mode_id]);
page.Keys("[F12]");
}
function switchIEBrowserMode_UnitTest(){
switchIEBrowserMode("ie8");
}