Javascript - events don't fire on some mobile phon
Community Forums/General Help/Javascript - events don't fire on some mobile phon
| ||
| Hi all, the following (simple) code has a couple of events that don't fire on some phones. At first it didn't work on ios so I added the ontouchstart event...but on particular android phones it doesn't work either. Am I doing something wrong? What I'm aiming for is the ability to detect a click on the body of the webpage...which is initially empty (but should still have a 'body' as such!) and then is replaced with a background of a image chosen at random from a list... It works on desktop and on my mobile, and on iPad (after adding ontouchstart) but doesn't seem to work on some other phones... I thought javascript was fairly standard?
<html>
<body onmousedown=changeimage() ontouchstart=changeimage()>
</body>
</html>
<script>
var time = new Date();
var milli = time.getTime();
function changeimage()
{
time = new Date();
if(time.getTime() - milli > 1000)
{
milli = time.getTime();
}
else
{
return;
}
document.body.style.background = "url(images/image"+(Math.floor(Math.random()*253)+1)+".jpg)";
document.body.style.backgroundColor = "#111111";
document.body.style.backgroundSize = "contain";
document.body.style.backgroundRepeat = "no-repeat";
document.body.style.backgroundPosition = "center";
}
</script>
|
| ||
| Seems okay....user error - impatient not waiting for download..... |