我需要做一個按鈕,將工作在每一個頁面和瀏覽器,可以複製文本區域的輸入。我想用下面的函數來做到這一點:複製到剪貼板在mozzila firefox純粹的JavaScript功能
selectElementContents: function(){
el = document.getElementById("tag_text");
var range = document.createRange();
range.selectNode(el);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
try {
var successful = document.execCommand('copy');
} catch(err) {
console.log('Oops, unable to copy');
}
這是目前除Firefox和Safari瀏覽器都工作正常。我讀了一些關於Safari的內容,似乎它不支持這種功能,或者我誤會了?但是,當我嘗試使用document.execCommand('copy')複製輸入內容時,它會引發以下錯誤:[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1" data: no]
。我查了這個錯誤,它是一種通用的,因爲代碼出現在多個錯誤中。
最後我的問題是如何使它在Firefox上工作,出了什麼問題?
這可能有助於http://stackoverflow.com/questions/21696052/copy-to-clipboard-with-javascript-in-firefox – vidriduch
我不能創建一個插件。此功能必須適用於銷售產品的每個網站。 –
netscape.security.PrivilegeManager。 vidriduch你知道那是什麼嗎? –