Safari 浏览器下  select 不能window.open ,  button 却可以
为什么?怎么解决这个问题呢? 
<!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>
    <title>测试</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>    <select id="sl">
        <option value="1">百度1</option>
        <option value="2">百度2</option>
        <option value="3">百度3</option>
        <option value="4">百度4</option>
        <option value="5">百度5</option>
    </select>    <input type="button" id="btn" value="跳转" />
    <script type="text/javascript">        document.getElementById('sl').onchange = function () {
             window.open('http://www.baidu.com')
        };        document.getElementById('btn').onclick = function () {
            window.open('http://www.baidu.com')
        };    </script></body>
</html>Safaribug百度HTML浏览器

解决方案 »

  1.   

    自己顶~另外在补充一下。Safari 下, select 的 onchange 事件中,不用window.open的方式,用form表单提交的方式也会阻止
      

  2.   

    是选中了。浏览器默认是选中的状态。但是 为啥  button 中就不会阻止呢?
      

  3.   

    不用window.open的方式,用form表单提交的方式也会阻止
    re:
    贴出你表单瞧瞧
      

  4.   

    window.open  如果是用户主动触发的话就不会被阻止,如果由脚本自动触发就会被阻止在button 中的click添加,是属于 用户主动触发 不会被阻止,运行正常但是在 select 的 onchange中却异常了
      

  5.   


    在页面中加这段
    <form id="myform" method="get" action="http://www.baidu.com" target="_blank"></form>然后onchange的时候执行 
    document.getElementById('myform').submit();
      

  6.   

    然后onchange的时候执行 
    document.getElementById('myform').submit();
    re:
    哪个标签onchange的时候
      

  7.   


    代码如下:
      
    <select id="sl">
            <option value="1">百度1</option>
            <option value="2">百度2</option>
    </select>
    <form id="myform" method="get" action="http://www.baidu.com" target="_blank"></form>
         document.getElementById('sl').onchange = function () {
               document.getElementById('myform').submit(); 
         };
      

  8.   

    找到解决办法了 
    select标签中,在onchange中不能写window.open,但是在click的时候可以执行window.open所以我们可以这样写可以解决
    <select id="sl">
            <option value="1">百度1</option>
            <option value="2">百度2</option>
    </select>
    <input type="hidden" value="1" id="hid" />document.getElementById('sl').onchange = function () {
         var that = this;
         setTimeout(function(){
              document.getElementById('hid').value = that.value;
         },0);
    };
    document.getElementById('sl').onclick = function () {
         var oldval = document.getElementById('hid').value;
         if(this.value != oldval){
              window.open('http://www.baidu.com')
         }
    };
      

  9.   

    把你form中的target属性拿掉也是没问题的<!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>
        <title>测试</title>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    </head>
    <body>
     
     <form id="myform" method="get" action="http://www.baidu.com">
     
        <select id="sl" onchange="fun1()">
            <option value="1">百度1</option>
            <option value="2">百度2</option>
            <option value="3">百度3</option>
            <option value="4">百度4</option>
            <option value="5">百度5</option>
        </select>
     
        <input type="button" id="btn" value="跳转" />
     </form>
     
        <script type="text/javascript">
     
            function fun1(){
               document.getElementById('myform').submit();
            }
            document.getElementById('btn').onclick = function () {
                window.open('http://www.baidu.com')
            };
     
        </script>
     
    </body>
    </html>
      

  10.   

    <!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>
        <title>测试</title>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <style>
            .select{
                display:inline-block;
                border: solid 1px blue;
                width: 100px;
                padding: 10px;
                text-align: center;
            }
            .select>div{        }
            .select>input{
                display: none;
            }
            .select:hover>div{
                display: none;
            }
            .select:hover>input{
                display: block;
                width: 100%;
                margin-top: 5px;
                margin-bottom: 5px;
            }
        </style>
    </head>
    <body>
        <div class="select">
            <div>选择</div>
            <input type="button" id="btn1" value="百度" />
            <input type="button" id="btn2" value="百度" />
            <input type="button" id="btn3" value="百度" />
            <input type="button" id="btn4" value="百度" />
            <input type="button" id="btn5" value="百度" />
            <input type="button" id="btn6" value="百度" />
        </div>
     
     
        <script type="text/javascript">
            for(var i = 1; i<=6;i++)
            document.getElementById('btn' + i ).onclick = function () {
                window.open('http://www.baidu.com');
            };
     
        </script>
     
    </body>