I use html5 wysiwyg editor.编辑器以动态方式加载 iframe,我想在此编辑器上监视keydown
事件。
加载的 iframe 如下所示:
<iframe class="wysihtml5-sandbox" security="restricted" allowtransparency="true">
<html>
<head><meta charset="UTF-8"></head>
<body marginwidth="0" marginheight="0" id="descriptionkb" contenteditable="true"
class="form- control editor wysihtml5-editor" spellcheck="true"
style="color: rgb(85, 85, 85); cursor: auto; font-family: Arial, Helvetica, sans-serif;
font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal;
line-height: 20px; letter-spacing: normal; text-align: start; text-decoration: none;
text-indent: 0px; text-rendering: auto; word-break: normal; word-wrap: break-word;
word-spacing: 0px; background-color: rgb(255, 255, 255);">
<span id="_wysihtml5-undo" class="_wysihtml5-temp"></span>
</body>
</html>
</iframe>
我监视keydown
事件所做的是:
$('iframe.wysihtml5-sandbox').contents().on('keydown', '#descriptionkb', function(e){
// execute code on keydown event
});
这适用于chrome和IE,但不适用于Mozilla。我尝试了不同的方法来访问事件,但没有一种在 Mozilla 中起作用。我错在哪里?
引用
自 https://github.com/xing/wysihtml5/wiki/Events
在注册之前,请确保 wysihtml iframe 已完全加载 此类事件,否则结果可能因浏览器而异。单程 要确保 iframe 已完全加载,需要定义诸如 以上作为编辑器"加载"函数的回调。