我在嘗試構建一個WYSIWYG
,並且我有三個按鈕:copy
,cut
和paste
。在所見即所得中複製,剪切和粘貼文本
我試過這個腳本的每一個,但它沒有奏效。
這是我的腳本:
//Copy
document.getElementById('copy').addEventListener('click', function(){
document.execCommand('copy', false, null);
}, false);
//Cut
document.getElementById('cut').addEventListener('click', function(){
document.execCommand('cut', false, null);
}, false);
//Paste
document.getElementById('paste').addEventListener('click', function(){
document.execCommand('paste', false, null);
}, false);
在Google chrome
,Internet Explorer 11
,Safari
和Opera
沒有他們中的一個已經工作了,我沒有得到在控制檯東西。
在Mozilla Firefox
我得到這個消息:
Error: Permission denied for <file://> to get property Clipboard.cutcopy
document.execCommand('cut', false, null);
爲copy
和paste
同樣的事情。
我該如何解決這個問題?
檢查此鏈接了: http://stackoverflow.com/questions/1817441/javascript-document-execcommand-cross-browser –