Jump to content

Opera Does Not Get Canvas Handle


Mackenzie17
 Share

Recommended Posts

Hi I'm a little new to JavaScript and I am trying to make a small program using an HTML5 canvas. However, when the following code is executed:function Prog(){ var self = this; this.init = function() { var d = document; self.canvas = d.getElementById("can"); self.c = self.canvas.getContext("2d");...}var p = new Prog();p.init();The code works in the other major browsers, but in opera, it throws an error saying "cannot convert self.canvas to object" or sometimes just "self.canvas is null"Thanks in advance

Edited by Mackenzie17
Link to comment
Share on other sites

hi Ingolmethanks for replying, I tried replacingself.c = self.canvas.getContext("2d"); withself.c = d.getElementById("can").getContext("2d"); with that code the error console says"Cannot convert 'd.getElementById("can")' to object"the script is deferred so the page should be loaded before the script is executed thanks

Edited by Mackenzie17
Link to comment
Share on other sites

It's possible that you're trying to access the element before it has loaded.
how/when are you calling this function in relation to the page loading? Can we see the full code? (JS/HTML) The best practice would be to have it run within the window.onload event handler. Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...