🔒 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
  • 350
    Views
  • 1
    Participants
Last reply from:
James_Mikes

Online now

Members online
1,073
Guests online
817
Total visitors
1,890

Forum statistics

Threads
2,276,991
Posts
28,973,649
Members
1,229,682
Latest member
JhayPureno13
Back
Top