javascript - 试图创建一个自动点击脚本
问题描述
您好,我目前在一个具有第三方聊天框插件的网站上工作。该应用程序在开箱即用的弹出窗口中没有计时器控件,因此我想尝试模拟单击聊天按钮以使其比默认计时器更快出现。
该按钮位于本网站的右下角: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);"
有谁知道我该怎么做?
解决方案
使用.click()
而不是.trigger('click')
. .trigger
是一个 jQuery 方法,但您引用的是内置对象,因此请改用适当的内置方法:
setTimeout(() => {
document.getElementById('iframe-designstudio-button')
.contentWindow.document.getElementById('iframe-button-container').click();
}, 1000);
推荐阅读
- arrays - C:如何将输入作为未知大小的矩阵
- json - react useState setState 在首次加载时未定义,但在刷新后可以正常工作
- powerbi - Power BI 检查值是否在某个时间之前发生
- c++ - 如何删除从基类继承的纯虚函数?
- mac-catalyst - 移植到 Mac 催化剂时排除“FirebaseAnalytics”吊舱
- sql - 如何计算 Oracle SQL 中行之间的百分比增加?
- php - WP缓存插件阻止cookie被设置
- python - 获取 AttributeError:ResultSet 对象没有属性“美化”。使用 BeautifulSoup 时
- c# - 带有基本模型的视图模型中的 ASP.NET Core MVC 模型验证
- javascript - 导航失败,因为页面崩溃!JavaScript 剧作家