ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – iPad Safari IOS 5 window.close()关闭错误的窗口

2019-10-07 20:47:30  阅读:201  来源: 互联网

标签:javascript mobile-safari ipad


我们有一个iPad应用程序正在我们的旧iPad上工作.

我们使用打开外部链接
var x = window.open(url)

在一天结束时,当用户关闭应用程序的这一部分时,我们会浏览它打开的所有窗口并为每个窗口执行x.close(),一切都很好.

使用IOS 5和可爱标签在新iPad上进行测试,
打开新窗口(尽管现在它们以标签打开)很好,但是做x.close()似乎不一定要关闭x,它可能会关闭窗口y或z.执行x.focus()或y.focus()工作正常,正确的选项卡成为焦点,但关闭似乎只是选择它想要的任何选项卡.

这是一个错误还是我做错了什么?示例程序:

<html>
<head></head>
<body>
    <script>
        //The openWindow array will hold the handles of all open child windows
        var openWindow = new Array();
       var win1;
       var win2;
        //Track open adds the new child window handle to the array.
        function trackOpen(winName) {
            openWindow[openWindow.length]=winName;
        }

        //loop over all known child windows and try to close them.  No error is
        //thrown if a child window(s) was already closed.
        function closeWindows() {
            var openCount = openWindow.length;
            for(r=openCount-1;r>=0;r--) {
                openWindow[r].close();
            }
        }

        //Open a new child window and add it to the tracker.
        function open1() {
            win1 = window.open("http://www.yahoo.com");
            trackOpen(win1);
        }

        //Open a different child window and add it to the tracker.
        function open2() {
            win2 = window.open("http://www.google.com");
            trackOpen(win2);

        }
        //Open whatever the user enters and add it to the tracker
        function open3() {
            var newURL = document.getElementById("url").value;
            var win3= window.open(newURL);
            trackOpen(win3);
        }

    </script>
    <input type="button" value="Open 1" onclick="open1()">
    <input type="button" value="Open 2" onclick="open2()">
    <input type="button" value="Focus 1" onclick="win1.focus()">
    <input type="button" value="Focus 2" onclick="win2.focus()">
    <input type="button" value="Close 1" onclick="win1.close()">
    <input type="button" value="Close 2" onclick="win2.close()">

    URL: <input type="text" id="url"> <input type="button" value="Open URL" onclick="open3()">
    <input type="button" value="Close All" onclick="closeWindows()">

</body>
</html>

解决方法:

这对我来说很有用(iPad 2和3; 3和iOS 5.1.1)

var host=window.opener;
window.focus(); /* solves the iPad3 problem */
window.close(); /* the actual closing we want to achieve... */
/* makes the focus go back to opener on iPad2, fails silently on iPad3 */
try { host.focus(); } catch(e) {} 

标签:javascript,mobile-safari,ipad
来源: https://codeday.me/bug/20191007/1868773.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有