8

これが私が試したすべてのコードです:

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

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

Webアプリモードの場合、画面は更新されるだけで、その場所には移動しません。モバイルSafariでは、意図したとおりに機能します。

これはiPhoneのWebアプリの制限ですか?それを回避する方法はありますか?

完全なコードは次のとおりです。

<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)モバイル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 に答える