0

I'm trying to attach an event listener to my video element. I'd like to start the video if the variable played is less than 1. And then open the link the next time you tap on the video if it's already playing (played > 0). But when I test this on my iPad it's opening the link and playing the video together.

Here's my code...

    var played = 0;
    var video = document.getElementById('video');
    video.addEventListener("touchstart", openLink, false);

    function openLink() {
            if (played == 0) {

                video.play();
                played++;

            } else if (played != 0){

                open("internal-http://example.com", "_blank");

            }
        }

Can someone point me in the right direction? I've tried "click" and "touchstart" as my events but somehow the browser (UIWebview) is doing both at the same time.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Forgot to mention this is running inside an app. The open link will open up another webview. – user3460854 Dec 07 '15 at 15:26
  • On touch devices, you have two events, unlike in a normal browser. First is hover and the other is click. You might be executing both of the events one after another... Please tell me if this is the issue. – Technotronic Dec 07 '15 at 15:37
  • You can find a detailed explanation here: http://stackoverflow.com/questions/8503453/click-event-called-twice-on-touchend-in-ipad – Technotronic Dec 07 '15 at 16:03
  • Possible duplicate of [Click event called twice on touchend in iPad](https://stackoverflow.com/questions/8503453/click-event-called-twice-on-touchend-in-ipad) – Brian Tompsett - 汤莱恩 Nov 10 '19 at 11:41
  • @BrianTompsett-汤莱恩 - not sure why you're editing so many old questions (which brings them into the surface again and makes them show up in people's feeds). Many questions you're editing are considered off-topic today (like, questions from 2010 & 2011). For example: [this one](https://stackoverflow.com/questions/3097600/what-are-the-best-light-weight-solutions-for-drag-and-drop) - no reason to edit that question, as it's now 100% off-topic; if anything, it should be voted as such, and left as-is. – David Makogon Nov 10 '19 at 13:33

0 Answers0