首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jQuery在页面重新加载后隐藏iframe id

问使用jQuery在页面重新加载后隐藏iframe id
EN

Stack Overflow用户
提问于 2017-10-09 22:24:53
回答 1查看 133关注 0票数 1

在使用jQuery重新加载页面后,我有一个关于隐藏iframe id的问题。我有一个外部实时聊天(使用以下iframe )

代码语言:javascript
复制
<iframe id="customer-chat-iframe" name="mcs_1380166852448_" src="https://testlivechat.test.com/php/app.php?widget-iframe-content" marginwidth="0" marginheight="0" frameborder="0" allowfullscreen="" style="background: transparent; border: none; outline: none; position: fixed; display: block; z-index: 999999; bottom: -355px; right: 30px; overflow: hidden; min-width: 279px; min-height: 368px; width: 340px; height: 400px; margin: 0px; padding: 0px;"></iframe>

在外部网站中调用实时聊天。

代码语言:javascript
复制
<script type="text/javascript" src="//testlivechat.test.com/php/app.php?widget-init.js"></script>

我的要求是最初我需要隐藏聊天框(在整个页面重新加载之后),然后在单击某些特定事件时,如按钮单击,聊天框应该会显示出来。

我用jquery尝试了同样的方法,但最初无法隐藏。

不起作用的代码:

代码语言:javascript
复制
(function( $ ) { 
 $('#customer-chat-iframe').hide(); 
})(jQuery);
EN

回答 1

Stack Overflow用户

发布于 2017-10-09 22:29:08

尝试使用JS Cookie:

代码语言:javascript
复制
/** This is load on page ready. **/
$( document ).ready(function() {
  var isCookieSet = getCookie("c_chat"); 
  if(isCookieSet == "" || isCookieSet == null){
    $('#customer-chat-iframe').css("display", "none");
  }
  else{
    $('#customer-chat-iframe').css("display", "block");
  }
});


/*Function to get cookie value **/
function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
        c_start = c_start + c_name.length + 1;
        c_end = document.cookie.indexOf(";", c_start);
        if (c_end == -1) {
            c_end = document.cookie.length;
        }
        return unescape(document.cookie.substring(c_start, c_end));
    }
  }
  return "";
}




/** This will execute on click of radio button and set the cookie **/
function onRadioButtonClicked(){
  var isCookieSet = getCookie("c_chat"); 
  if(isCookieSet == "" || isCookieSet == null){
    document.cookie = "c_chat=1";
  }
  $('#customer-chat-iframe').css("display", "block");
}

您需要在单选按钮上调用"onRadioButtonClicked()“。如果这对你有效,请告诉我

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46648762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档