OnClick事件在移动浏览器中不起作用

时间:2015-04-10 07:07:56

标签: javascript jquery html mobile

我有一个html页面,其中我在div标签中添加了onclick事件。在那个onclick事件中,我使用了location.href = url来打开任何url。 它在Web浏览器中运行良好,但在移动浏览器中不起作用。 这是什么原因? 我的代码是 -

<html class="swipebox-html swipebox-touch">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<link rel="stylesheet" href="../css/swipebox.css">
<script src="../js/jquery-2.1.0.min.js"></script>
<script src="../js/jquery.swipebox.js"></script>
<script type="text/javascript">
    jQuery(function($) {
        window.onload = function(e) {
            e.preventDefault();
            $.swipebox([ {
                href : '../img/sari1.jpg'
            }, {
                href : '../img/sari2.jpg'
            }, {
                href : '../img/sari3.jpg'
            }, {
                href : '../img/sari4.jpg'
            } ]);
            $(".slide")
                    .attr(
                            "onclick",
                            "document.location.href='http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias%3Daps&field-keywords=saris+&rh=i%3Aaps%2Ck%3Asaris+'");
        }
    });
</script>
</head>
<body class="touching">
    <div id="swipebox-overlay" style="width: 360px; height: 640px;"
        class="">
        <div id="swipebox-container">
            <div id="swipebox-slider"
                style="display: block; transition: transform 0.4s ease; -webkit-transition: transform 0.4s ease; -webkit-transform: translate3d(0%, 0px, 0px); transform: translate3d(0%, 0px, 0px);">
                <div class="slide current"
                    onclick="document.location.href='http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias%3Daps&amp;field-keywords=saris+&amp;rh=i%3Aaps%2Ck%3Asaris+'">
                    <img src="../img/sari1.jpg">
                </div>
                <div class="slide"
                    onclick="document.location.href='http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias%3Daps&amp;field-keywords=saris+&amp;rh=i%3Aaps%2Ck%3Asaris+'">
                    <img src="../img/sari2.jpg">
                </div>
                <div class="slide"
                    onclick="document.location.href='http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias%3Daps&amp;field-keywords=saris+&amp;rh=i%3Aaps%2Ck%3Asaris+'"></div>
                <div class="slide"
                    onclick="document.location.href='http://www.amazon.in/s/ref=nb_sb_noss_2?url=search-alias%3Daps&amp;field-keywords=saris+&amp;rh=i%3Aaps%2Ck%3Asaris+'"></div>
            </div>
            <a id="swipebox-close"
                style="background-image: url(file:///C:/Users/AmitDas/OBDWorkspace/mobileCatalogue/src/frontend/web/img/icons.svg);"></a>
        </div>
    </div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

对于移动浏览器,我们可以通过点击而不是点击来使用touchstart事件。 通过这个我解决了我的问题。