Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

325
Views
How to programmatically click on a button and after a particular time in Javascript and jQuery | Bypass popup blocking in web Browsers

I was developing an application that programmatically shows a popup after 5 seconds, but i found out that web browsers like firefox, chrome, internet explorer, etc. were blocking the popup.

Popup blocking In the past, evil sites abused popups a lot. A bad page could open tons of popup windows with ads. So now most browsers try to block popups and protect the user.

Most browsers block popups if they are called outside of user-triggered event handlers like onclick

By default modern web browsers block popups triggered by a function or code. But does not block popups triggered by clicking on buttons.

// popup blocked
window.open('https://javascript.info');

// popup allowed
button.onclick = () => {
  window.open('https://javascript.info');
};

So i had to bypass their blocking policy by programmatically clicking on the button after 5 seconds to still initiate the same popup.

So i decided to post this as a question and also answer it by myself for those that might be facing the same issue.

Step 1. Create a button, give it and ID and pass a function name on the onClick

<button id="buttonID" onclick="trigerPopup()"></button> 

Step 2 Create trigerPopup function

function trigerPopup(){
        alert("Hello I am poping up after 5 seconds");
        //your code goes here
}

Step 3 After 5 seconds, programmatically clicked on button

    window.setTimeout(function () {

        //this will trigger a click on the button
        const buttonID = document.getElementById('buttonID').click();


   }, 5000);

Thanks guys

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Step 1. Create a button, give it and ID and pass a function name on the onClick

<button id="buttonID" onclick="trigerPopup()"></button> 

Step 2 Create trigerPopup function

function trigerPopup(){
        alert("Hello I am poping up after 5 seconds");
        //your code goes here
}

Step 3 After 5 seconds, programmatically clicked on button

    window.setTimeout(function () {

        //this will trigger a click on the button
        const buttonID = document.getElementById('buttonID').click();


   }, 5000);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!