I have a large canvas with an interactive Processing sketch that i want to run as soon as the page is loaded. For some reason when the user clicks on the screen (on the canvas) for the first time, the page scrolls down a tiny bit. It is annoying because the user misses the click target when interacting with the sketch for the first time (wait until text "click on any species" appears).
http://417i.com/alcazar-vegetal/
I have tried focusing the canvas element on page load, also clicking via javascript, and even preventDefault, but nothing worked.
<!DOCTYPE html>
<html>
<head>
<meta name="Alcazar Vegetal" CONTENT="Alcazar Vegetal">
<title>Alcazar Vegetal</title>
<script src="processing-1.4.1.min.js"></script>
<script>
document.onload = function() {
var elem = document.getElementById("main_canvas");
elem.click();
elem.focus();
elem.preventDefault();
}
</script>
<style>
canvas{border:0px;margin:0px;padding:0px;outline:none;}
canvas:focus{outline:none;}
</style>
</head>
<body bgcolor="white" style="color:rgb(20,20,20)">
<canvas datasrc="alcazar_vegetal_viz_Pjs.pde" tabindex="1"></canvas>
<br>
<br>
</body>
</html>