移动Safari web

编程入门 行业动态 更新时间:2024-10-24 06:28:41
移动Safari web-app添加到主屏幕时,window.open()不起作用(window.open() doesn't work in mobile Safari web-app added to home screen)

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

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

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

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; }

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

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

Here is the complete code:

<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>

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

最满意答案

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

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

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();

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

更多推荐

本文发布于:2023-07-31 02:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Safari   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!