IE9 how to prevent the browser default event

I'm IE6-8, chrome18 version of the above are possible

function stopDefault( e ) {
//To prevent the default browser action(W3C)
if ( e && e.preventDefault )
e.preventDefault();
//IE is the default action way stop function
else
window.event.returnValue = false;
return false;
}


But now needs to be compatible with IE9, but always can not be used, appeal to God you know?

Started by Algernon at December 17, 2016 - 12:50 PM

IE9 preventDefault can be
You have a look there is no other fault code that should be no problem

Posted by Prescott at December 29, 2016 - 1:02 PM

Try this

function stopDefault(e) {
var ev = e || window.event;
if(ev.preventDefault) {
ev.preventDefault();
} else {
ev.returnValue = false;
}
return false;
}

Posted by Ritchie at January 05, 2017 - 2:18 PM

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<link href="" rel="stylesheet" type="text/css"/>
<style type="text/css">
body{height:1500px;}
.box{height:200px;width:200px;overflow:auto;margin:200px auto;border:1px solid blue;}
</style>
</head>
<body>
<ul class="box" id="list">
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>



<script type="text/javascript">
preventScroll("list");

function preventScroll(id){
var _this = document.getElementById(id);
if(navigator.userAgent.indexOf("Firefox")>0){
_this.addEventListener('DOMMouseScroll',function(e){
_this.scrollTop += e.detail > 0 ? 60 : -60;
e.preventDefault();
},false);
}else{
_this.onmousewheel = function(e){
e = e || window.event;
_this.scrollTop += e.wheelDelta > 0 ? -60 : 60;
return false;
};
}
return this;
}


</script>

</body>
</html>

Posted by Ivy at January 06, 2017 - 1:44 PM