window.open()在添加到主屏幕的移动Safari Web应用程序中不起作用 [英] window.open() doesn't work in mobile Safari web-app added to home screen

查看:93
本文介绍了window.open()在添加到主屏幕的移动Safari Web应用程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我尝试的所有代码:

Here is all the code I've tried:

select:function(event, ui) {
    window.open(ui.item.value, "_blank");
}

select:function(event, ui) {
    window.location.href = ui.item.value;
}

在网络应用模式下,屏幕只是刷新,它不会去到位置。在Mobile Safari中,它按预期工作。

When in web app mode, the screen just refreshes, it doesn't go to the location. In Mobile Safari, it works as intended.

这是否限制了iPhone上的网络应用程序?有没有办法呢?

Is this a limiting with web apps on iPhone? Is there a way around it?

这是完整的代码:

<script>
$(document).ready(function() {
    var cct = $('input[name=csrf_token]').val();    
    var searchInput = $('input[name=search]');

    function loadEventsData(onSuccess){
      $.ajax({
        type: 'POST',
        url: '<?php echo site_url('ajax_frontend/getEventsSearch'); ?>',
        dataType: 'json',
        success: onSuccess,
        error: function(XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }
      });
    }

    function initializeEventsAutocomplete(data){
      searchInput.addClass('loaded').autocomplete({
      source:data,
      appendTo: '.search_autocomplete',
      minLength:2,
      delay:0,
      selectFirst:false,
      open: function(event, ui) {
        $('ul.events').hide();
        $('.ui-autocomplete').removeAttr('style');
        $('.icon-search').hide();
        $('.icon-close').show();
      },
      close: function(event, ui) {
        val = searchInput.val();
        searchInput.autocomplete("search", val);
        searchInput.focus();
        return false;
      },
      select:function(event, ui) {
        window.location.href = ui.item.value;
        return false;
      }
      });
    }

    $('form').submit(function(e) {
        e.preventDefault();
        searchInput.blur();
    });

    searchInput.keyup(function(){
    if($(this).is(".loaded")) return;
    loadEventsData(initializeEventsAutocomplete);
    });

    $('.icon-close').click(function(e) {
        e.preventDefault();

        $(this).hide();
        $('.icon-search').show();
        searchInput.autocomplete('close');
        $('ul.events').show();
        searchInput.val('');
    });
});
</script>

这里是JSON(其中一些):

And here is the JSON (some of it):

[{"value":"http:\/\/events.dev\/index.php\/event\/canada-day","label":"Canada Day"},{"value":"http:\/\/events.dev\/index.php\/event\/triathlon-festival","label":"Triathlon Festival"}]


推荐答案

我想出来了。我正在使用以下代码阻止Web应用程序中的链接在Safari中打开:

I figured this out. I'm using the following code to prevent links in the web app from opening in Safari:

https://gist.github.com/1042026

这导致了一些不必要的副作用。为了解决这个问题,我补充说:

This was causing some unwanted side effects. To fix this, I added:

event.stopPropagation();

event.stopPropagation();

到我的选择:功能区域,它可以正常工作。

to my selection:function area and it works as it should.

这篇关于window.open()在添加到主屏幕的移动Safari Web应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆