IE11下,CKEditor在Bootstrap Modal中的下拉问题

本文介绍了一个在IE11浏览器中使用CKEditor与Bootstrap Modal时出现的兼容性问题及解决方案。当在Modal中加载CKEditor时,格式、字体和颜色的下拉菜单会在显示后立即消失。文章提供了一种通过修改Bootstrap源码来解决该问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原问题解决方案链接:

 

最近在项目中需要在Bootstrap Modal弹出框中载入CKEditor。

初始化CKEditor以后,在IE11下,格式/字体/颜色的下拉会闪现一下后就消失,但在chrome和firefox下没问题。

主要原因是IE11下,点击CKEditor,触发了focusin.modal事件,原modal enforceFocus函数的if条件成立,bootstrap modal获取焦点,CKEditor下拉失去焦点,所以下拉出现闪现。

Google了以后找到了一个解决方案,http://ckeditor.com/forums/CKEditor/Editor-Dropdowns-dont-work-in-IE11

这个解决方案中,加了判断后,可以避免modal获取焦点,但好像modal一直都不会trigger了。

 

我做了一下修改,以下代码是在原modal enforceFocus函数的基础上添加了!$(e.target.parentNode).closest(".cke").length判断条件,也就是说在原判断条件+未点击在CKEditor上,则modal获取焦点。

代码的执行顺序是jQuery、bootstrap再执行此段代码。

$.fn.modal.Constructor.prototype.enforceFocus = function() {
    $(document)
      .off('focusin.bs.modal')
      .on('focusin.bs.modal', $.proxy(function (e) {
        if (document !== e.target &&
            this.$element[0] !== e.target &&
            !this.$element.has(e.target).length &&
            !$(e.target.parentNode).closest(".cke").length) {
            
            this.$element.trigger('focus')
        }
      }, this))
};

在项目中测试了一下未发现问题。

 

附 bootstrap.js中enforceFocus函数代码对比

Modal.prototype.enforceFocus = function () {
    $(document)
      .off('focusin.bs.modal') // guard against infinite focus loop
      .on('focusin.bs.modal', $.proxy(function (e) {
        if (document !== e.target &&
            this.$element[0] !== e.target &&
            !this.$element.has(e.target).length) {
          this.$element.trigger('focus')
        }
      }, this))
  }

this.$element表示modal对象。

转载于:https://www.cnblogs.com/yulj/p/7081092.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值