进入页面自动执行点击事件,跳转的有些快,注意看那一瞬间的变化!
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>测试</title></head><body><a id="aid" href="/qq_42618566" οnclick="alert('clicked');">触发onclick</a><script>// 进入页面立即触发(()=>{// 兼容IEif(document.all) {document.getElementById("aid").click();}// 兼容其它浏览器else {var e = document.createEvent("MouseEvents");e.initEvent("click", true, true);document.getElementById("aid").dispatchEvent(e);}})();/*// 也可写个定时器进行触发setTimeout(()=>{// 兼容IEif(document.all) {document.getElementById("aid").click();}// 兼容其它浏览器else {var e = document.createEvent("MouseEvents");e.initEvent("click", true, true);document.getElementById("aid").dispatchEvent(e);}},3000); // 3秒后执行*/</script></body></html>
立即执行:
定时执行: