1
<!DOCTYPE html>
<HTML>
<HEAD>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
video {
  right: 0;
  bottom: 0;
  min-width: 50%;
  min-height: 50%;
  max-width: 90%;
  max-height:90%;
  width: auto;
  height: auto;
</style>
</HEAD>
<BODY bgcolor=black>
<center><video width="853" height="480" autoplay="autoplay">
  <source src="file:///C:/Program Files/NARUTO SHIPPUDEN Ultimate Ninja STORM 2/IntroMovie.mp4" type="video/mp4" />
  Your browser does not support HTML5 video.
</video></center>
</BODY>
<script type="text/javascript">
document.body.addEventListener("onclick", function(){
    alert("Hello! I am an alert box!!");
});
document.body.addEventListener("oncontextmenu", function(){
    alert("Hello! I am an alert box!!");
});
document.body.addEventListener("onkeypress", function(){
    alert("Hello! I am an alert box!!");
});
</script>
</HTML>

For some reason whenever I click on the body (Whether inside or outside of the video) the alert boxes don't pop up.

Is there any reason why the code isn't showing the alert boxes?

0

1 Answer 1

2

It should be:

document.body.addEventListener("click", function(){
    alert("Hello! I am an alert box!!");
});

You're adding an unnecessary 'on' in front of each action (which is necessary with attachEvent, but not addEventListener).

Should be:

  • click
  • keypress
  • contextmenu
  • etc
Sign up to request clarification or add additional context in comments.

3 Comments

That definitely solved it! Thanks for the quick response! (When stackexchange will let me, I will add it as the best answer.)
@GameAnalysis you should have the ability now, glad I could help!
As a side-note, keypress wasn't working for some reason but keydown works fine!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.