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

编程入门 行业动态 更新时间:2024-10-25 10:25:45
本文介绍了iPad Safari IOS 5 window.close()关闭错误的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们的iPad应用程序正在使用我们较旧的iPad。

We have an iPad application that's working on our older iPads.

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

We open external links using var x = window.open(url)

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

at the end of the day, when the user closes this part of the app, we go through all the windows it opened and do x.close() for each one and everything is okie dokie.

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

Testing on the new iPad with IOS 5 and the lovely tabs, opening the new windows (although now they open as tabs) is fine, but doing x.close() doesn't seem to necessarily close x, it may close window y or z. Doing x.focus() or y.focus() works just fine, the correct tab comes into focus, but close seems to just pick whatever tab it wants.

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

Is this a bug or am I doing something wrong? Example program:

<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("www.yahoo"); trackOpen(win1); } //Open a different child window and add it to the tracker. function open2() { win2 = window.open("www.google"); 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)

That did the trick for me (iPad 2 and 3; 3 with 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) {}

更多推荐

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

本文发布于:2023-11-09 15:33:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572743.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   错误   Safari   iPad   IOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!