window.open() 在添加到主屏幕的移动 Safari 网络应用程序中不起作用



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

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

在网络应用程序模式下,屏幕只会刷新,不会转到该位置。在Mobile Safari中,它可以按预期工作。

这是iPhone上的网络应用程序的限制吗?有办法绕过它吗?

这是完整的代码:

<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(其中一些):

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

通过编程(Javascript)在Mobile Safari中打开一个链接。如果您不能使用标准的html链接,但必须使用Javascript:,则是理想的选择

var a = document.createElement("a");
a.setAttribute('href', facebook);
a.setAttribute('target', '_blank');
a.click();

我想明白了。我使用以下代码来阻止网络应用程序中的链接在Safari:中打开

https://gist.github.com/1042026

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

event.stopPropagation();

到我的selection:function区域,它正常工作。

最新更新