简体   繁体   English

按 Z 键重定向不起作用

[英]Pressing the Z key to redirect isn't working

            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
<script>
   

 var keyPressed = event.originalEvent.code;
                  if(keyPressed == 'KeyZ'){
                      location.replace("https://classroom.google.com");
                  }
        </script>

When clicking the Z key, nothing happens, however when I try it on a different project.单击 Z 键时,什么也没有发生,但是当我在另一个项目上尝试它时。 The link is avackgames.xyz链接是avackgames.xyz

In this case, you should use the 'keydown' event listener.在这种情况下,您应该使用“keydown”事件监听器。

For more information please visit this website.... ( Click here )欲了解更多信息,请访问此网站......( 点击这里

This is the JavaScript code you should add to your HTML file code.这是您应该添加到 HTML 文件代码中的 JavaScript 代码。 I hope it's clear and helpful, Thanks!.我希望它是清晰和有帮助的,谢谢!

 <script> //Create event listener for 'keydown' window.addEventListener('keydown', KeyPressed) //Create a function with 'event' parameter function KeyPressed(event) { //Checking if Z key pressed, For your information, the code '90' is for the Z key. if (event.keyCode == 90) { //To be sure that the 'Z' key was pressed, let's show an alert message. alert('Yeeess, you clicked Z key!') } } </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM