最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Undo and Redo in WYSYWYG contentEditable in SWT doesn't work - Stack Overflow

programmeradmin2浏览0评论

I'm doing a WYSYWYG HTML5 editor With SWT by setting the contentEditable attribute of the body tag to true.

When I'm executing some mands like document.execCommand('bold'), it works perfectly. But when I try to undo an operation with document.execCommand('undo') nothing happens. I don't know if I have to set any undo manager or to do something like that. Can you help me please ?

I'm doing a WYSYWYG HTML5 editor With SWT by setting the contentEditable attribute of the body tag to true.

When I'm executing some mands like document.execCommand('bold'), it works perfectly. But when I try to undo an operation with document.execCommand('undo') nothing happens. I don't know if I have to set any undo manager or to do something like that. Can you help me please ?

Share Improve this question edited Nov 16, 2012 at 3:11 lc. 117k21 gold badges161 silver badges188 bronze badges asked Jul 20, 2012 at 12:20 JbprodJbprod 2092 silver badges8 bronze badges 1
  • 2 Does this help stackoverflow./a/5062713/903454 – 5hahiL Commented Nov 24, 2012 at 10:50
Add a ment  | 

2 Answers 2

Reset to default 1

This appears to be a mon problem as Google search will reveal. The following site has a good patibility table and demo for testing.

  • Table: http://www.quirksmode/dom/execCommand.html
  • Demo: http://www.quirksmode/dom/execCommand/

They also have the following statement on the demo page:

Undo/Redo doesn't work in IE. The problem is that the changes in the textarea to the right are also added to the Undo/Redo stack. There will be no textarea in the final version, so it's not necessary to solve the problem.

According to this quirksmode table, undo/redo works in all major browsers, but it has this note:

Undo works in Safari, but if you do Undo/Redo too often, it crashes. Solved in 3. If you make your own changes in the editable area, Undo/Redo continues to work in Mozilla and Safari (though it ignores your custom changes), but in IE and Opera it stops working.

I don't know how SWT might affect this, but it might be better to use

document.execCommand("undo", "", null)

ExecCommand has always been very buggy, and I don't know much about SWT, but I hope this helps you.

发布评论

评论列表(0)

  1. 暂无评论