🔒 Closed Automatic Press Letter "Z" when page load

Status
Not open for further replies.

James_Mikes

Honorary Poster
baka po may nakakaalam nito patulong naman po kung pwede or may idea kayo papaano so basically gusto kong mag auto press yung letter "Z" sa keyboard after load nang page ayaw kasi gumana tama po ba yung code ko ?.

HTML:
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="./main.css">
    <style>
    
        </style>
</head>
<body>
     <a href="javascript:void(0)" class="premier-doc-landing_rating-hover_link upvote" data-cha-location="top" data-cha-action-target-type="document" data-cha-action-target-id="29890385" data-cha-action-type="rate_helpful" data-cha-target-name="helpful_btn">
        <i class="fa fa-fw fa-thumbs-up" aria-hidden="true"></i>Vote</a>


        <input type="text" placeholder="test" />

</body>
</html>


JavaScript:
 window.addEventListener("load", function() {

 

 

   // get the element in question
   const input = document.getElementsByTagName("input")[0];

   // focus on the input element
   input.focus();
  
   // add event listeners to the input element
   input.addEventListener('keypress', (event) => {
    console.log("You have pressed key: ", event.key);
     document.getElementsByClassName("premier-doc-landing_rating-hover_link upvote")[0].click();
   });
  
  
  
   // dispatch keyboard events
   input.dispatchEvent(new KeyboardEvent('keypress',  {'key':'z'}));
  
  



 
 });
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 359
    Views
  • 1
    Participants
Last reply from:
James_Mikes

Trending Topics

Online now

Members online
1,229
Guests online
3,548
Total visitors
4,777

Forum statistics

Threads
2,308,417
Posts
29,184,932
Members
1,191,977
Latest member
hestermind
Back
Top