您好我目前正在开发一个拥有第三方聊天框插件的网站。该应用程序没有开箱即用弹出窗口的定时器控件,所以我想尝试模拟聊天按钮上的点击,使其显示早于默认计时器。
该按钮位于本网站的右下角: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);"
有谁知道我该怎么做?
答案 0 :(得分:1)
使用.click()
而不是.trigger('click')
。 .trigger
是一个jQuery方法,但您引用了内置对象,因此请使用适当的内置方法:
setTimeout(() => {
document.getElementById('iframe-designstudio-button')
.contentWindow.document.getElementById('iframe-button-container').click();
}, 1000);
答案 1 :(得分:1)
您可以直接使用..
window.frames['iframe-designstudio-button'].contentWindow.document.getElementById("designstudio-button-text").click();
打开聊天窗口。
<script>
function haveclicked(){
window.frames['iframe-designstudio-button'].contentWindow.document.getElementById("designstudio-button-text").click();
}
</script>
<body data-rsssl="1" onload="setTimeout('haveclicked();',3000);"