首页 > 解决方案 > 试图创建一个自动点击脚本

问题描述

您好,我目前在一个具有第三方聊天框插件的网站上工作。该应用程序在开箱即用的弹出窗口中没有计时器控件,因此我想尝试模拟单击聊天按钮以使其比默认计时器更快出现。

该按钮位于本网站的右下角:https ://familyoffices.com/

我试图命中的代码是:(此代码是从插件提供的脚本生成的)

<iframe id="iframe-designstudio-button- 
style="border:none;display:block;" name="designstudio-button- 
frame" title="Live Chat Button" scrolling="no" class="iframe-button- 
text" height="34" width="113"></iframe>
<html class="wf-droidsans-n4- 
 active wf-active"><head><meta name="viewport" content="width=device- 
 width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> 
<title>Live Chat Button</title> 
<link rel="stylesheet" 
 href="https://fonts.googleapis.com/css?family=Droid+Sans:400" 
media="all"> <style type="text/css"></style> 
</head> <body> 
<div id="iframe-button-container" style="height: 34px; width: 
 113.265625px;">
<div id="iframe-button-content" class="button-text" 
 style="bottom: 0px; right: 0px;"> 
<span id="designstudio-button- 
text">Chat with us..</span>
</div> </div> </body> </html>

我使用了这个 Javascript,但我无法让它工作。

 (this is above the body)
  <script>
 function haveclicked(){
 document.getElementById('iframe-designstudio- 
 button').contentWindow.document.getElementById('iframe-button- 
 container').trigger('click');
  }
 </script>

 <body data-rsssl="1" onload="setTimeout('haveclicked();',3000);"

有谁知道我该怎么做?

标签: javascriptwordpress

解决方案


使用.click()而不是.trigger('click'). .trigger是一个 jQuery 方法,但您引用的是内置对象,因此请改用适当的内置方法:

setTimeout(() => {
  document.getElementById('iframe-designstudio-button')
    .contentWindow.document.getElementById('iframe-button-container').click();
}, 1000);

推荐阅读