i am new at html5 and javascript. i have written a basic code for canvas and i have button on html page ,its simple alert. issue is that its working fine(alert box poping out) for IE-9 , OPERA , chrome but for firefox nothing happens.
kindly point out where i am committing a mistake.
here is my code
<script>
if(window.addEventListener) {
window.addEventListener('load', function ()
{
var my = new Array();
var i=0;
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var imageObj = new Image();
var imageObj1 = new Image();
imageObj.onload = function(){
imageObj1.src = "Sunflower.gif";
context.drawImage(imageObj, 0, 0);
}
imageObj.src = "Crystal-outline.gif";
change.addEventListener('mousedown', function () {ButtonDown (change)}, false);
function ButtonDown (change)
{ alert('welcome to my page');}
init();
}, false); }
</script>
</head>
<body >
<canvas id="myCanvas" width="870" height="150">
</canvas><br>
<button id="change" type="button">Change</button>
</body>
thanks in advance.
In the following line you’re not getting the change element by id but instead trying to call the addEventListener method on it directly where as there is no such object in js. Other browsers allow you to do this for the sake of running badly written scripts.
it should be changed to
document.getElementById('change').addEventListener('mousedown', function () {ButtonDown (this)}, false);Also you need to pass
thisas the method parameter