我正在处理一个遗留项目,在一个页面中有一些JS代码,即使我在IE 11中运行,也强制将该兼容模式更改为该页面的IE 5。
我编写了以下代码,适用于IE 5以外的所有浏览器。
//Mouse Special back buttons trap code start
function PreventBrowserBack(){
window.location.hash="1";
window.location.hash="2";
}
PreventBrowserBack();
$(window).on('hashchange', function() {
window.location.hash="1";
});
function ApproveBrowserBack(){
window.location.hash="1";
window.location.hash="2";
}
//Mouse Special back buttons trap code End
document.onmousedown = function disableclick(event){
if(event.button==2)
{
alert("Right Click is not allowed");
return false;
}
};
因为当我们转到此页面时,某些JS代码强制将兼容模式设置为IE 5,所以此代码无法正常工作。
请帮帮我。 提前谢谢。
答案 0 :(得分:0)
使用navigator.userAgent
获取浏览器版本,例如if(navigator.userAgent== ...
document.getElementById("browserVer").innerHTML = navigator.userAgent;

<p id="browserVer"> </p>
&#13;