Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. html button not firing on mobile, oh

html button not firing on mobile, oh

Scheduled Pinned Locked Moved The Weird and The Wonderful
helpcsharpjavascripthtmlasp-net
6 Posts 3 Posters 10 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • raddevusR Offline
    raddevusR Offline
    raddevus
    wrote on last edited by
    #1

    File this one under Weird...or annoying. Background Created a little web app (including dotnet core Web Api) that allows me to read comics more easily. Because, I mean, why not. I wanted to be able to save the date of the last comic I read to a remote location so I can then load it from any browser (any of my multiple devices) and keep reading the comics consecutively by date. I got it all working and it's a fun little hobby app. The Problem I pulled the app up on my TV via Amazon FireStick (runs Amazon Silk browser). It all loaded up great. Then I attempted to press the button and nothing happened.

    Load Dates

    onclick Not Supported On Mobile This is considered a mobile browser and onclick is not supported. You need the touchstart event. First Attempt to Fix I looked it up and found documentation. I figured you could just add the ontouchstart="functionName()" to the button. Nope! You have to attach the event to the element using javascript.

    document.querySelector("#loadComicDatesButton").addEventListener("touchstart",getComicDatesFromApi);

    I guess that is because the <button> element doesn't know about ontouchstart or something?? :~ Other devs have probably figured this out and said this 1 million times before. But, it is still weird.

    Richard DeemingR M 2 Replies Last reply
    0
    • raddevusR raddevus

      File this one under Weird...or annoying. Background Created a little web app (including dotnet core Web Api) that allows me to read comics more easily. Because, I mean, why not. I wanted to be able to save the date of the last comic I read to a remote location so I can then load it from any browser (any of my multiple devices) and keep reading the comics consecutively by date. I got it all working and it's a fun little hobby app. The Problem I pulled the app up on my TV via Amazon FireStick (runs Amazon Silk browser). It all loaded up great. Then I attempted to press the button and nothing happened.

      Load Dates

      onclick Not Supported On Mobile This is considered a mobile browser and onclick is not supported. You need the touchstart event. First Attempt to Fix I looked it up and found documentation. I figured you could just add the ontouchstart="functionName()" to the button. Nope! You have to attach the event to the element using javascript.

      document.querySelector("#loadComicDatesButton").addEventListener("touchstart",getComicDatesFromApi);

      I guess that is because the <button> element doesn't know about ontouchstart or something?? :~ Other devs have probably figured this out and said this 1 million times before. But, it is still weird.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      I thought browsers were supposed to fire the mouse events as well as the touch events for single-finger activation gestures? Touch Events - Level 2[^] Even Amazon's own documentation say they do: Touch - Amazon Silk[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      raddevusR 2 Replies Last reply
      0
      • raddevusR raddevus

        File this one under Weird...or annoying. Background Created a little web app (including dotnet core Web Api) that allows me to read comics more easily. Because, I mean, why not. I wanted to be able to save the date of the last comic I read to a remote location so I can then load it from any browser (any of my multiple devices) and keep reading the comics consecutively by date. I got it all working and it's a fun little hobby app. The Problem I pulled the app up on my TV via Amazon FireStick (runs Amazon Silk browser). It all loaded up great. Then I attempted to press the button and nothing happened.

        Load Dates

        onclick Not Supported On Mobile This is considered a mobile browser and onclick is not supported. You need the touchstart event. First Attempt to Fix I looked it up and found documentation. I figured you could just add the ontouchstart="functionName()" to the button. Nope! You have to attach the event to the element using javascript.

        document.querySelector("#loadComicDatesButton").addEventListener("touchstart",getComicDatesFromApi);

        I guess that is because the <button> element doesn't know about ontouchstart or something?? :~ Other devs have probably figured this out and said this 1 million times before. But, it is still weird.

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #3

        The "inconsistency" of what events are supported in the HTML vs. events that can only be wired up with addEventListener is basically why I always use addEventListener. Besides the fact that I rather despise the whole "on[event]="someFunctionCall()" in the HTML. Makes it a PITA to figure out where to change the handler, and I also use a "UI event router" for these things so they can be handled by actual object instances, logged, etc. Yes yes, I know, you're doing a fun web app. ;)

        Latest Articles:
        Abusing Extension Methods, Null Continuation, and Null Coalescence Operators

        raddevusR 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          I thought browsers were supposed to fire the mouse events as well as the touch events for single-finger activation gestures? Touch Events - Level 2[^] Even Amazon's own documentation say they do: Touch - Amazon Silk[^]


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          raddevusR Offline
          raddevusR Offline
          raddevus
          wrote on last edited by
          #4

          Interesting. That's what I had expected too. But, until I added the explicit touchstart event I was getting nothing. I even tested it with a simple alert(). And, once I added it, it started working. So documentation may say something, but we all know the _real documentation_ is the code. :rolleyes: Thanks for finding those though because i couldn't find those docs. I will read them more closely. :thumbsup:

          1 Reply Last reply
          0
          • M Marc Clifton

            The "inconsistency" of what events are supported in the HTML vs. events that can only be wired up with addEventListener is basically why I always use addEventListener. Besides the fact that I rather despise the whole "on[event]="someFunctionCall()" in the HTML. Makes it a PITA to figure out where to change the handler, and I also use a "UI event router" for these things so they can be handled by actual object instances, logged, etc. Yes yes, I know, you're doing a fun web app. ;)

            Latest Articles:
            Abusing Extension Methods, Null Continuation, and Null Coalescence Operators

            raddevusR Offline
            raddevusR Offline
            raddevus
            wrote on last edited by
            #5

            Marc Clifton wrote:

            basically why I always use addEventListener. Besides the fact that I rather despise the whole "on[event]="someFunctionCall()" in the HTML.

            I like that you made those points. I will keep that in mind. Yours is a much better Separation of Concerns anyways. I believe the lesson I've just learned (new convention for me) is that it is better to wire up events in the JS itself due to your point and the point that mine didn't work very well. Thanks again.:thumbsup:

            1 Reply Last reply
            0
            • Richard DeemingR Richard Deeming

              I thought browsers were supposed to fire the mouse events as well as the touch events for single-finger activation gestures? Touch Events - Level 2[^] Even Amazon's own documentation say they do: Touch - Amazon Silk[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              raddevusR Offline
              raddevusR Offline
              raddevus
              wrote on last edited by
              #6

              Closing the loop on this... That second link explains that the onclick event should fire and it is correct. I created another barebones HTML page and added a button with an onclick event and tried it from my Amazon Kindle fire pad (running Silk browser) and it worked with no problem. Hmmm...maybe I had a syntax error on my original HTML and it pre-cluded the touch event from firing properly while a normal desktop browser handled it?? :~ Well, thanks again for your help. :thumbsup:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups