Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8128037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:44:43+00:00 2026-06-06T07:44:43+00:00

I have a very simple HTML5 game that works as expected from a regular

  • 0

I have a very simple HTML5 game that works as expected from a regular browser, but when accessed from a browser on an iPhone or iPad, it does not recognize the click event or the touchstart event.

The original code is from a tutorial located here:
http://www.lostdecadegames.com/how-to-make-a-simple-html5-canvas-game/

I have modified it and added a click event which will move the smiley face to wherever you click on the canvas. This click event works fine from Mac and Windows browsers with a mouse:
http://iwebss.com/test

But if you access it with an iPhone or iPad, the click event does not work. I also tried adding an additional listener for touchstart, which does not work either.

These are the new listeners I added to the code:

    addEventListener("click", mouseClickEvent, false);
    function mouseClickEvent(e) {
        alert("click event");
            mouseClick = true;
        if (e.offsetX) {
              mouseX = e.offsetX;
              mouseY = e.offsetY;
            }  else if(e.layerX) {
              mouseX = e.layerX;
              mouseY = e.layerY;
            }
    }

    addEventListener("touchstart", testEvent, false);
    function testEvent(e) {
        alert("touchstart event");
    }

Any ideas on what I am doing wrong, or how to read iPhone and iPad touch events?

EDIT: I also tried the mousedown event which also does not work.

RESOLVED: I figured it out… see my answer below.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:44:44+00:00Added an answer on June 6, 2026 at 7:44 am

    Ok, I figured it out … although the event listener works in a regualr browser, for iphone/ipad you need to specifically attach it to the canvas.

    So in my given example, I have:

    var canvas = document.createElement("canvas");

    So this worked in regular browsers, but NOT on iphone/ipad:

    addEventListener("click", mouseClickEvent, false);

    SOLUTION: This is what I had to do to get it to work on iphone/ipad (add the canvas. in front):

    canvas.addEventListener("click", mouseClickEvent, false);

    This also worked for the touchstart event as well!

    As a side note, I wonder if it matters whether you use touchstart or click event on iphone??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple webapp that runs within HTML5's Canvas that doesn't have
This is a very simple game I'm trying to write but I have a
So I have 4 pages. They are very simple. index.php (WORKS) <html> <form action=upload.php
I have developed a very simple Android native app to launch my HTML5 webapp.
I just made a simple HTML5 game for mobile webkit. I have made a
I'm working on a simple JavaScript game using HTML5 canvas. It's a very typical
This is prob. very simple but I can't get it. I have a href
i have a very simple demo for cross domain communication in iframes using html5's
I have a very simple html page with the following javascript in it $(function()
I have a very simple HTML/JS code, which expands the size of a div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.