Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript iPhone WebApp在safari中打开链接_Javascript_Iphone_Mobile Safari_Web Applications - Fatal编程技术网

Javascript iPhone WebApp在safari中打开链接

Javascript iPhone WebApp在safari中打开链接,javascript,iphone,mobile-safari,web-applications,Javascript,Iphone,Mobile Safari,Web Applications,当我将我的“web应用程序”添加到iPhone的主屏幕上,然后打开它并单击一个链接时,就会打开Safari 对于我的问题,我找到了一些解决方案,但它们似乎不起作用: 你的链接 这两篇文章/教程都是在iOS5之前编写的。有新的方法吗?我做错什么了吗 感谢您的帮助一个想法是让您的主屏幕应用程序成为一个iframe,并让所有主播都瞄准它。不需要javascript 或者: $('a').on('click touchend', function(ev){ $(this).prevent

当我将我的“web应用程序”添加到iPhone的主屏幕上,然后打开它并单击一个链接时,就会打开Safari

对于我的问题,我找到了一些解决方案,但它们似乎不起作用:

你的链接
这两篇文章/教程都是在iOS5之前编写的。有新的方法吗?我做错什么了吗


感谢您的帮助

一个想法是让您的主屏幕应用程序成为一个iframe,并让所有主播都瞄准它。不需要javascript

或者:

$('a').on('click touchend', function(ev){

    $(this).preventDefault();
    window.location = $(this).attr('href');

});
不要将“touchstart”用于链接之类的内容。您只想检测用户何时停止触摸链接。检测按键、鼠标点击等同样的事情。您想要检测的事件结束


.live在最新版本的jQuery中已被弃用,因此从现在开始使用.on(),它可以无缝地包装现有和非现有元素。

我就是您所指文章的作者。我仍然使用我的javascript方法,它对我来说很好。touchstart适用于web应用程序,因为浏览器渲染它需要更长的时间。如果你打算制作一个本地应用程序,那么就不要使用它,但我已经为许多应用程序使用了touchstart,它工作得很好

谢谢
Jake Boyles

此javascript代码适用于iOS 5(它适用于我):

在head标签中:

<script type="text/javascript">
function OpenLink(theLink){
    window.location.href = theLink.href;
}
</script>

函数OpenLink(theLink){
window.location.href=theLink.href;
}
在要在同一窗口中打开的链接中:

<a href="(your website here)" onclick="OpenLink(this); return false"> Link </a>


代码基于以下注释:

这在iPhone 5上运行良好

$(document).ready(function(){

    // Stop the default behavior of the browser, which
    // is to change the URL of the page.
    $("a").click(function(event){
        event.preventDefault();
        // Manually change the location of the page to stay in
        // "Standalone" mode and change the URL at the same time.   
        window.location = $(this).attr('href');
    });
 });

记得链接到最新版本的jQuery。

你有什么问题?你只说明了发生了什么。可能是
<a href="(your website here)" onclick="OpenLink(this); return false"> Link </a>
$(document).ready(function(){

    // Stop the default behavior of the browser, which
    // is to change the URL of the page.
    $("a").click(function(event){
        event.preventDefault();
        // Manually change the location of the page to stay in
        // "Standalone" mode and change the URL at the same time.   
        window.location = $(this).attr('href');
    });
 });