试图让iPhone上的链接工作

时间:2015-09-01 09:14:08

标签: javascript html ios css iphone

我正在使用HTML5,我有一个奇怪的问题,我已经开始制作一个网站但是当我测试网站时,我发现在某个页面上iPhone上的链接似乎不起作用。它的HTML:

<a href="link">
   <div>
       <img src="img" />
   </div>
</a>

对于css,我尝试了一些方法,增加a标签的z-index,增加高度和宽度。下面是样本css:

a {
   display:block;
   z-index:999;
   height:200px;
   width:300px;
}

还尝试添加一些javascript,我从另一个stackover问题中找到:

$(function () {          
        IS_IPAD = navigator.userAgent.match(/iPad/i) != null;
        IS_IPHONE = (navigator.userAgent.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPod/i) != null);

        if (IS_IPAD || IS_IPHONE) {

            $('a').on('click touchend', function () {
                var links = $(this).attr('href');
                window.open.replace(links); // opens in new window as requested
                return false; // prevent anchor click    
            });
        }
    });

但仍然没有运气

更新 问题似乎在iphone 5s上解决了,但在iphone 5c上却没有解决

更新 这似乎与苹果iphone软件的最新更新有关

2 个答案:

答案 0 :(得分:1)

<!-- Script provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
<DIV id='mydiv'></DIV>

<a href="hovytech.github.io">
    <img src="img.png"></img>
</a>

jsFiddle

答案 1 :(得分:0)

的JavaScript

<!DOCTYPE html>
<html>
    <head>
        <script>
            function openLink() {
                //Replace current window
                //window.open("http://hovytech.github.io", "_self");
                //Open new window
                window.open("http://hovytech.github.io", "_blank");
            }
        </script>
    </head>
    <body>
        <img src="http://hovytech.github.io/Images/HovyTech.png" width="self" height="100px" onclick="openLink()"></img>
    </body>
</html>

希望这种方法适合你。