简体   繁体   中英

Set delay on click event

I want to load this script after loading the page so I want to set a delay for this code to work -

document.getElementsByClassName("pdp-button_theme_bluedaraz")[0].click();

If by "delay" you mean a timer and a function which is called after the timer finishes you might want to use setTimeout() function. argument 1 is the function to be called and argument 2 is the countdown time in milliseonds eg:

 setTimeout(exec, 2000); function exec() { document.getElementsByClassName("pdp-button_theme_bluedaraz")[0].click(); }

or if you mean execute the script after page has loaded try this

 document.onload = function() { document.getElementsByClassName("pdp-button_theme_bluedaraz")[0].click(); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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