javascript 如何在单击按钮时显示实时聊天对话框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29790154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:03:55  来源:igfitidea点击:

How to show live chat dialog box on click of button?

javascriptjqueryhtmlcssjquery-ui

提问by Zee

I want to show a live chat form in my website which will open on click of a button. The chat form that I need to show is in a separate file. How can I do that using jquery? It also needs to be responsive.

我想在我的网站中显示一个实时聊天表单,单击按钮即可打开该表单。我需要显示的聊天表单在一个单独的文件中。我如何使用 jquery 做到这一点?它还需要响应。

Something like this: https://www.websitealive.com/

像这样的东西:https: //www.websitealive.com/

回答by Nandan Bhat

Try this solution, This is just a layout. Just add a chat form inside the chatBox. Just Copy-Paste the complete code.

试试这个解决方案,这只是一个布局。只需在 chatBox 中添加一个聊天表单即可。只需复制粘贴完整的代码。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Simple Chatbox</title>
<style type="text/css">
.chat-box {
    position:fixed;
    right:15px;
    bottom:0;
    box-shadow:0 0 0.1em #000;
}

.chat-closed {
    width: 250px;
    height: 35px;
    background: #8bc34a;
    line-height: 35px;
    font-size: 18px;
    text-align: center;
    border:1px solid #777;
    color: #000;
}

.chat-header {
    width: 250px;
    height: 35px;
    background: #8bc34a;
    line-height: 33px;
    text-indent: 20px;
    border:1px solid #777;
    border-bottom:none;
}

.chat-content{
    width:250px;
    height:300px;
    background:#ffffff;
    border:1px solid #777;
    overflow-y:auto;
    word-wrap: break-word;
}

.box{
    width:10px;
    height:10px;
    background:green;
    float:left;
    position:relative;
    top: 11px;
    left: 10px;
    border:1px solid #ededed;
}

.hide {
    display:none;
}
</style>
</head>
<body>
<div class="chat-box">
<div class="chat-closed"> Chat Now </div>
<div class="chat-header hide"><div class="box"></div>Online Support</div>
<div class="chat-content hide">

*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
Your chat content...
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
Your chat content...
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
*<br>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".chat-closed").on("click",function(e){
        $(".chat-header,.chat-content").removeClass("hide");
        $(this).addClass("hide");
    });

    $(".chat-header").on("click",function(e){
        $(".chat-header,.chat-content").addClass("hide");
        $(".chat-closed").removeClass("hide");
    });
});
</script>
</body>

</html>

回答by Guruprasad Rao

You can load form into an iframe as below

您可以将表单加载到 iframe 中,如下所示

"https://www.websitealive3.com/9/operator/guest/gDefault_v2.asp?cframe=chat&groupid=9&websiteid=77&departmentid=23&operatorid=21139&sessionid_=347739&iniframe=dock"

" https://www.websitealive3.com/9/operator/guest/gDefault_v2.asp?cframe=chat&groupid=9&websiteid=77&departmentid=23&operatorid=21139&sessionid_=347739&iniframe=dock"

<iframe id="iframe_window" style="visibility:visible;width: 400px; height: 525px; border: 1px solid rgb(214, 214, 214); right: 20px; bottom: -1px; display: none" onload="this.style.visibility = 'visible';" src="Your file url"></iframe>

add an element which loads the iframe. I would assume an atag as below

添加一个加载iframe. 我会假设一个a标签如下

<a class="load_chat" href="#">Chat with us</a>

and write a js click event for above a

并为上面写一个js点击事件 a

$('.load_chat').on('click',function(){
      $("#iframe_window").css('display','inline');
});