OnClick event does not work in mobile browser

I have an html page in which I added the onclick event in the div tag. In this onclick event, I used location.href = url to open any url. It works fine in a web browser, but does not work in a mobile browser. What is the reason for this? My code is

<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>
-4
source share
1 answer

For a mobile browser, we can use the touchstart event with a click, and not without a click. And with that I solved my problem.

0
source

Source: https://habr.com/ru/post/1685843/


All Articles