window.close() doesn't work on iOS

不羁岁月 提交于 2019-11-30 13:12:10

here is what I ended up getting to work...
never could get the window.close function to work; even in the setTimeout as shown above

I tested this on:
    windows XP : Chrome20,Firefox12,IE8
    Android gingerbread : android browser
    Android Ice Cream : android browser, Firefox
    Ipad : default browser (i assume its safari)
    Iphone 3gs and 4s : default


<SCRIPT LANGUAGE=\"JavaScript\">
    function refresh() {
        var sURL = unescape("http://(some web page)/");
        window.location.replace(sURL);
    }
    function closeWindow() {
        var isiPad = navigator.userAgent.match(/iPad/i) != null;
        var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
        if (isiPad || isiPhone) {
           setTimeout( \"refresh()\", 300 );
        } else {
           window.close();
        }
    }
</SCRIPT>

...... and the html code .......

<p><input class="bigbutton" type="button" name="cancel" id="cancel" value="Cancel" onClick="closeWindow()"></p>

After some searching, I found this tweet which posts a workaround - https://twitter.com/#!/gryzzly/statuses/177061204114685952 by @gryzzly

Copied here in full

window.close() doesn't work on iOS after window.open()ing or target="_blank"? do setTimeout(window.close, timeout); where timeout > 300.

This along with removing a .focus() in which I focus on the parent window before closing the new window completely solved the problem for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!