2012-07-23 62 views
7

这是所有我已经试过代码:window.open()在加入到主屏幕上移动的Safari Web的应用程序无法正常工作

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

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

当Web应用程序模式下,屏幕只是刷新,它不会去的位置。在移动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"}] 
+0

你确定这不是一个问题了'选择:function'称自己?如果你做了另一个JavaScript而不是打开一个窗口,它是否工作? – ceejayoz 2012-07-23 19:09:04

+0

看起来你是对的。我把它放在'select:function'之外,它可以工作。但不幸的是,我仍然需要它。我正在使用jQuery UI自动完成。任何想法可能会阻止它以及如何克服它? – dallen 2012-07-23 19:12:52

+0

您可以显示完整的自动填充电话吗?我猜想这是你错过的简单的东西,但没有确定的代码很难说。 – ceejayoz 2012-07-23 19:14:11

回答

1

我想通了这一点。我使用下面的代码,以防止开放的Web应用程序链接在Safari:

https://gist.github.com/1042026

这是造成一些不必要的副作用。为了解决这个问题,我补充道:

event.stopPropagation();

我的selection:function区域,它的工作原理应该如此。

1

以编程方式(Javascript)在Mobile Safari中打开链接。 理想的,如果你不能用一个标准的HTML链接,但你必须使用JavaScript:

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