window.open()在Android上从setTimeout调用时返回undefined

And*_*rey 5 javascript android

我的Android模拟器上有奇怪的行为.当从setTimeout或回调函数调用时,window.open()总是返回undefined,例如AJAX回调.但是,当从事件处理程序调用时,window.open()会成功打开一个弹出窗口,例如onclick这里是示例代码:

<html>
<head>
</head>
    <body>
    <script type="text/javascript">
    function fnc()
    {
      setTimeout(function() { alert(window.open('about:blank')) }, 100);
    }
    </script>
    <input type="button" onclick="fnc()" value="push me">
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

在示例警报(window.open('about:blank'))中显示'undefined'并且未创建弹出窗口从fnc()直接调用时,同样的函数有效

有任何想法吗?

谢谢

Dro*_*ror 3

请尝试以下操作:

<html>
    <head>
        <script type="text/javascript">
            function go(){
                window.open('about:blank');
            }
            function fnc()
            {
                var buttonnode= document.createElement('input');
                buttonnode.setAttribute('type','button');
                buttonnode.setAttribute('name','sal');
                buttonnode.setAttribute('style','display:none;');
                document.body.appendChild(buttonnode);

                buttonnode.onclick = go;

                setTimeout(function() { buttonnode.click() }, 100);
            }
        </script>
    </head>
    <body>
    <input type="button" onclick="fnc()" value="do later"><br/>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)