简体   繁体   English

execCommand'undo'在Internet Explorer中无法正常工作

[英]execCommand 'undo' not working properly in Internet Explorer

In our project we are using Bootstrap WYSIWYG plugin ( http://mindmup.github.io/bootstrap-wysiwyg/ ) and we are facing a problem with Internet Explorer. 在我们的项目中,我们正在使用Bootstrap WYSIWYG插件( http://mindmup.github.io/bootstrap-wysiwyg/ ),并且Internet Explorer遇到了问题。 Although not officially supported, everything works in IE10 except the 'undo' and 'redo' actions. 尽管没有得到官方支持,但所有的功能都可以在IE10中正常工作,除了“撤消”“重做”动作。 This plugin relies on document.execCommand() to execute all the actions the user needs. 该插件依赖document.execCommand()来执行用户所需的所有操作。

You can test the issue in the demo editor in the plugin's site. 您可以在插件站点的演示编辑器中测试该问题。 Making some debug if you click the undo button you can see that document.execCommand('undo') is called but nothing happens. 如果单击“撤消”按钮进行一些调试,则可以看到调用了document.execCommand('undo') ,但没有任何反应。 However if you type the command in the console it does undo the last action. 但是,如果您在控制台中键入命令,它将撤消上一个操作。

I was thinking if this was an IE problem (as this works perfectly on Chrome and FF), but execCommand('undo') actually works -> http://jsfiddle.net/c8mq2/1/ 我在想这是否是IE问题(因为它在Chrome和FF上可以正常工作),但是execCommand('undo')实际上可以工作-> http://jsfiddle.net/c8mq2/1/

As we are using Backbone.js and in order to clarify wether if this was a plugin issue or not we dettached the undo button from the plugin and created a custom event like follows: 当我们使用Backbone.js时,为了弄清楚是否是插件问题,我们从插件上撤消了undo按钮,并创建了一个自定义事件,如下所示:

Backbone View: 骨干视图:

events: {           
        'click #undoAction': 'undoAction'
    },

undoAction: function (e) {
        e.preventDefault();
        document.execCommand('undo');
    }

HTML: HTML:

<div class="btn-group">
<!-- undo dettached from plugin -->
     <a class="btn" id="undoAction"><i class="icon-undo"></i></a>
<!-- redo keeps attached to plugin's data-edit attribute -->
     <a class="btn" data-edit="redo" "><i class="icon-repeat"></i></a>
</div>

However no luck here neither, it seems it is not a plugin issue. 但是这里也没有运气,似乎这不是插件问题。 What can be affecting to the IE's undo/redo stack that does not allow execCommand to work properly under some circumstances? 是什么会影响不允许execCommand在某些​​情况下正常工作的IE撤消/重做堆栈?

I cannot think on a different and straighter way of calling the execCommand('undo') as in the last Backbone example. 我无法想到像上一个Backbone示例中那样调用execCommand('undo')的另一种更直接的方法。 Any light on this would be highly appreciated! 任何对此的光将不胜感激!

UPDATE: New findings 更新:新发现

I found a way to make the undo action work and maybe this can show what is happening, but still don't understand why (you can try this in the bootstrap wysiwyg demo page above) -> 我找到了一种使撤消操作起作用的方法,也许它可以显示正在发生的事情,但是仍然不明白为什么(您可以在上面的bootstrap wysiwyg演示页面中尝试使用此方法)->

  1. Click on the textarea and input some text. 单击文本区域并输入一些文本。
  2. Click on the undo button 点击撤消按钮
  3. Result: nothing happens . 结果: 什么都没有发生
  4. Click on the textarea again. 再次单击文本区域。
  5. Move the cursor to the undo button (don't click on it yet) 将光标移动到撤消按钮(请不要单击它)
  6. Type some text without moving the cursor from the button. 键入一些文本,而无需从按钮移动光标。
  7. Click on the undo button 点击撤消按钮
  8. Result: IT WORKS 结果: IT工作
  9. Repeat steps 6 and 7 without moving the cursor and it will still work. 重复步骤6和7,而不移动光标,它仍然可以工作。

It seems that hovering the cursor into the undo button breaks the undo/redo stack and that's what makes document.execCommand('undo') stop working properly on those cases. 看来,将光标悬停在undo按钮上会破坏undo / redo堆栈,这就是document.execCommand('undo')在这些情况下停止正常工作的原因。 Is there any way to query that stack and see what is actually happening? 有什么方法可以查询该堆栈并查看实际发生了什么?

Thanks in advance! 提前致谢!

Thanks to the last findings I finally found the origin of the problem. 由于最后的发现,我终于找到了问题的根源。 The thing is that both Bootstrap WYSIWYG demo page and our own project are using the editor in conjunction with Bootstrap Tooltip plugin and thus everytime you hover a button the tooltip element is attached to the DOM. 事实是,Bootstrap WYSIWYG演示页面和我们自己的项目都将编辑器与Bootstrap Tooltip插件结合使用,因此,每当您将鼠标悬停在某个按钮上时,tooltip元素都将附加到DOM。 Somehow Chrome and Firefox don't take this element as a change that affects document.execCommand('undo') but Internet Explorer does. Chrome和Firefox不知何故不会将此元素视为影响document.execCommand('undo')的更改,但Internet Explorer会影响。

There may be other solutions but what we did was disabling tooltips for Internet Explorer browsers and relying on native titles on those cases. 可能还有其他解决方案,但是我们所做的是禁用Internet Explorer浏览器的工具提示,并在这些情况下依赖本机标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM