简体   繁体   English

在ios 6 Safari中从onchange函数调用时,window.open冻结

[英]window.open freezing when called from onchange function in ios 6 Safari

<select id="myDropDown" onblur='launchSite()'>
    <option value="selectone" selected="true">Select One</option>
    <option value="http://www.google.com">Google </option>
    <option value="http://www.cnn.com">CNN </option>
    <option value="http://www.espn.com">ESPN </option>
</select>


<script>

function launchSite()  {
    var el = document.getElementById("myDropDown");
    var url = el.options[el.selectedIndex].value;
    window.open(url);
}
 </script>

We have a web app that opens a new browser page when a certain values are selected from a dropdown. 我们有一个Web应用程序,当从下拉列表中选择某些值时,它会打开一个新的浏览器页面。 This worked fine in all previously tested browsers including Safari on ios 5. After the dropdown value is selected in ios 6, we get the Allow/Deny popup which is expected. 这在之前测试过的所有浏览器中运行良好,包括ios 5上的Safari。在ios 6中选择了下拉值后,我们得到了预期的Allow / Deny弹出窗口。 But then after making a selection on the popup Safari totally freezes. 但是在对弹出窗口进行选择后,Safari完全冻结了。 The strange thing is that this freezing does not happen every time. 奇怪的是,每次冻结都不会发生。 Only occasionally. 只是偶尔。 Is it possible this is a ios 6 bug? 这可能是ios 6的错误吗? I've tried onblur() like other questions have suggested but I still get ocassional freezing. 我已经尝试过onblur()就像其他问题一样,但我仍然会被冻结。 I am able to see the problem using the code above. 我能够使用上面的代码看到问题。

Thanks for any help! 谢谢你的帮助!

function launchSite(){
    window.setTimeout(function(){
        var el = document.getElementById("myDropDown");
        var url = el.options[el.selectedIndex].value;
        window.open(url);
    },100); }

Put this in the onchange event handler should solve the freezing problem 把它放在onchange事件处理程序中应解决冻结问题

We ran into a very similar issue when trying to call: 我们在试图打电话时遇到了一个非常类似的问题:

window.open(url, '_self')

in Chrome and Safari. 在Chrome和Safari中。 Instead, define where you want to open the window to: 而是,定义要打开窗口的位置:

window.open(url, '_blank')
or
window.open(url, '_new')

However, if you want to open as '_self', or the current window, then just call: 但是,如果你想打开'_self'或当前窗口,那么只需调用:

windown.location.href = url;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM