What's new

Help Automatic Press Letter "Z" when page load

James_Mikes

Honorary Poster
Established
Joined
May 23, 2021
Posts
243
Reaction
90
Points
155
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'}));
  
  



 
 });
 

Similar threads

Back
Top