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 9275085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:30:21+00:00 2026-06-18T16:30:21+00:00

The following code is working properly in other browsers except IE. My code is:

  • 0

The following code is working properly in other browsers except IE. My code is:

<script lang="javascript" type="text/javascript">
  alert("fdgdfgdfg");
  var canvas;
  var ctx;
  var canX;
  var canY;
  var rltvX;
  var rltvY;
  var x = "black";
  var flag = false;
  var w, h;
  function init() {
    alert("aaaaaaaaaaa");
    alert("bbbbbbbbbbb");
    canvas = document.getElementById("canvas");
    ctx = canvas.getContext("2d");
    w = canvas.width;
    h = canvas.height;
    canvas.addEventListener("mousemove", function(e) {findxy('move', e);}, false);
    canvas.addEventListener("mousedown", function(e) {findxy('down', e);}, false);
    canvas.addEventListener("mouseup", function(e) {findxy('up', e);}, false);
    canvas.addEventListener("mouseout", function(e) {findxy('out', e);}, false);
    canvas.addEventListener("touchstart", touchDown, false);
    canvas.addEventListener("touchmove", move, true);
    canvas.addEventListener("touchend", touchUp, false);
    document.body.addEventListener("mouseup", mouseUp, false);
    document.body.addEventListener("touchcancel", touchUp, false);
  }
  function findxy(res, e) {
    if (res == 'down') {
      canX = e.clientX - canvas.offsetLeft-5;
      canY = e.clientY - canvas.offsetTop-25;
      flag = true;
      dot_flag = true;
      if (dot_flag) {
        ctx.beginPath();
        ctx.fillStyle = x;
        ctx.fillRect(canX, canY, 2, 2);
        ctx.closePath();
        dot_flag = false;
      }
    }
    if (res == 'up' || res == "out") {
      flag = false;
    }
    if (res == 'move') {
      if (flag) {
        rltvX = canX;
        rltvY = canY;
        canX = e.clientX - canvas.offsetLeft-5;
        canY = e.clientY - canvas.offsetTop-25;
        ctx.beginPath();
        ctx.moveTo(rltvX, rltvY);
        ctx.lineTo(canX, canY);
        ctx.strokeStyle = x;
        ctx.lineWidth = 2;
        ctx.stroke();
        ctx.closePath();
      }
    }
  }
  function touchDown(e) {
    if (!e)
      var e = event;
    e.preventDefault();
    canX = e.targetTouches[0].pageX - canvas.offsetLeft-5;
    canY = e.targetTouches[0].pageY - canvas.offsetTop-25;
    ctx.beginPath();
    ctx.fillStyle = x;
    ctx.fillRect(canX, canY, 2, 2);
    ctx.closePath();
  }
  function move(e) {
    if (!e)
      var e = event;
    e.preventDefault();
    rltvX = canX;
    rltvY = canY;
    canX = e.targetTouches[0].pageX - canvas.offsetLeft-5;
    canY = e.targetTouches[0].pageY - canvas.offsetTop-25;
    ctx.beginPath();
    ctx.strokeStyle = x;
    ctx.lineWidth = 2;
    ctx.moveTo(rltvX, rltvY);
    ctx.lineTo(canX, canY);
    ctx.stroke();
  }
</script>

The error is, the object ‘canvas’ does not support the method addEventListener(). This is working properly in all browsers except IE. is there any alternative?

  • 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-18T16:30:22+00:00Added an answer on June 18, 2026 at 4:30 pm

    If you are using IE8 you should use the attachEvent() method instead of addEventListener(). This means you have to check first which browser the user has, then call the correct method on the element.

    EDIT for how to check which method to use:

    if (el.addEventListener){
      el.addEventListener(...); 
    } else if (el.attachEvent){
      el.attachEvent(...);
    }
    

    Where el is your DOM element.

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

Sidebar

Related Questions

can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>
i am using python 2.5.2 . The following code not working. def findValue(self, text,
In YUI I have following code working for mouse wheel. How do I make
We have the following code working for a complex rails form with checkboxes. I'm
Right now I have the following code working: @UiHandler(usernameTextBox) void onUsernameTextBoxKeyPress(KeyPressEvent event) { keyPress(event);
The following code is working great in a normal console application: private void button1_Click(object
Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
I am using the following code for my form validation. The code is working
On a Solaris 5.8 machine, I have the following code: [non-working code] char *buf;
The following code is not working: private void fileNameLinkButton_Click(object sender, RoutedEventArgs e) { HyperlinkButton

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.