8

这是我尝试过的所有代码:

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"}]
4

2 回答 2

3

以编程方式 (Javascript) 在 Mobile Safari 中打开一个链接。如果您不能使用标准 html 链接但必须使用 Javascript,则非常理想:

var a = document.createElement("a");
a.setAttribute('href', facebook);
a.setAttribute('target', '_blank');
a.click();
于 2014-04-17T14:03:43.077 回答
1

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

https://gist.github.com/1042026

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

event.stopPropagation();

到我的selection:function地区,它应该可以正常工作。

于 2012-07-24T00:58:13.147 回答