When my index page is fully loaded, I want to run a JavaScript function when clicked anywhere. Once it works, it should no longer work. Just first boot and first click.
My function is Website2APK.showInterstitialAd();
My index page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clown Nights</title>
<!-- Define the viewport -->
<meta name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1.01">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=10" />
<!-- Include the HTML5 API files -->
<script type="text/javascript" src="http://cdn.gameplayer.io/api/js/game.js"></script>
<script type="text/javascript" src="http://cdn.gameplayer.io/api/js/developer.js"></script>
<link rel="stylesheet" href="assets/game.css" type="text/css">
<script src="js/globalconfig.js"></script>
<script src="js/game.libs.js"></script>
<script src="js/game.js"></script>
</head>
<body>
<div id="gamediv"></div>
<!--<div id="loader"></div>-->
<canvas id="canvas" width="720" height="480" style="position: absolute; z-index: 1; display:block;"></canvas>
</body>
</html>
I tried the onload
and onclick
functions but I couldn’t.
2
Answers
I found the triggered function and fixed the problem.
this.newGameBtn.addEventListener('click', function() { Website2APK.showInterstitialAd();});
Simply add the event listener for
click
inside theonload
event ofwindow
object. Then remove theclick
event listener inside the onclick function usingdocument.removeEventListener()
. It takes two arguments, first is the event-type i.e.click
and second is the function that gets called on firingclick
event.