镶套iframe 鼠标滚动无效解决办法
背景:frameset 外面镶套一个页面
问题:IE鼠标滚动无效,chrome firfox 支持
解决:内页传递给父页进行滚动
代码:
<script type="text/javascript"> window.onload = function () { obj = window.parent.parent.document; if (obj != null && obj != undefined) { var a = ["DOMMouseScroll", "mousewheel"], chrome = navigator.userAgent.search(/chrome/i), delta = 0; if (document.attachEvent) { document.onmousewheel = onMouseWheel; } else if (chrome != -1) { document.addEventListener(a[1], onMouseWheel, false); } else { document.addEventListener(a[0], onMouseWheel, false); }; // function onMouseWheel(e) { var e = e || window.event; if (e.type == "mousewheel") { delta = e.wheelDelta / 12; } else { delta = e.detail / 3 * -10; }; if (chrome != -1) { } else { obj.documentElement.scrollTop -= delta; //阻止默认事件 if (e.preventDefault) { e.preventDefault(); } return false; } } } }; </script>
记录下,送给需要的同学