lundi 11 mai 2015

unable to run "canvas" tag and javascript program in aptana studio

Below shown is my HTMLcode :<!doctype html>

<html lang="en">

<title> </title>

`<head>`

<script scr ="myprog.js"> </script>

</head>

<body>

<section id="main">

<canvas id="canvas" width="600" height="400">

</canvas>

    </section>
</body>
</html>

And my javascript code is as below:

function doFirst(){

var x=document.getElementById('canvas');

canvas=x.getContext('2d');

canvas.strokeRect(10,10,100,200);

}

window.addEventListener("load",doFirst,false);

as per my understanding I'm suppose to get a rectangle of 100*200 in the browser(I'm using firefox browser). But here in my case, after running the above code I'm just getting a blank web page and I'm not getting any errors in the Aptana studio console too. Can anyone help me find out what the problem is?

I tried running a simple javascript program too ,to check if the my aptana studio can run javascript,and the following was the result:

1) when I added a button and tried to call a function using the below code,i got the alert after I clicked the button on the webpage(that is the program worked fine) : <input type="button" value="click me" onClick="alert('hello')/>;

2)But when I tried to run this particular code given below,i didn't get anything on my webpage:

doFunction() {

alert('hello');

}

window.addEventListener("load",doFirst,false);

document.getElementById("clickMe").onclick = "doFunction()";

3)I made sure that I linked my javascript file with my html using the code: <script src="my prog.js"></script> so the problem is not with the linking I guess.

Kindly please someone help me out... Thank you in advance...

Aucun commentaire:

Enregistrer un commentaire