js获取当前系统是不是win7,兼容ie,火狐,谷歌浏览器 的阻止事件冒泡


<html>
<head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <script src="http://code.jquery.com/jquery-latest.js"></script>
        
</head>
<body>
    <!-- 打开弹窗按钮 -->
<button onclick="test()">获取当前系统</button>
<button class="urlJump" data-type="1" >location.href</button>
<button class="urlJump" data-type="2" >top.window.location</button>
<div onclick="outdoor()" style="border: 1px solid red;width: 200px;height: 100px" >
    <p>最外层是一个父类的div</p>
    <div id="btn">
        
    </div>
</div>
    <script type="text/javascript">
        $(function () {
           $(".urlJump").on("click",function(){
                var type=$(this).attr("data-type");
                if(type =="" || type == null){
                    return;
                }
                if(type == "1"){
                    location.href="https://www.baidu.com/";
                }else {
                    top.window.location="https://www.iqiyi.com/";
                }
           });
           showbtn();

        });
        function test() {
           var ua = navigator.userAgent; 
           console.log(ua);
            if(ua.indexOf("Windows NT 6.1")!=-1) { 
                alert('您使用的是Win7系统!');
            } else { 
                alert('不是win7 ');
            }
        }

        function showbtn(){
             $("#btn").empty();
             var content='<button data-id="hihi" onclick="reload(event,this)">div里的button</button>';
             $("#btn").append(content);
        }
        function outdoor(){
              location.href="https://www.baidu.com/";
        }
        function reload(event,obj){
            stopEvent(event);
            var bool=window.confirm("确定要取消吗?");
            if(bool){
                alert("取消");
                var val = $(obj).attr("data-id");
            }
            
        }

       function stopEvent(event){ //阻止冒泡事件
     //取消事件冒泡
     var e=arguments.callee.caller.arguments[0]||event; //若省略此句,下面的e改为event,IE运行可以,但是其他浏览器就不兼容
     if (e && e.stopPropagation) {
     // this code is for Mozilla and Opera
     e.stopPropagation();
     } else if (window.event) {
     // this code is for IE
      window.event.cancelBubble = true;
     }
    }
    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值