В IE сделать это довольно безболезненно. Для Firefox вам нужно обновить users.js и / или prefs.js (вы можете поискать доступ к буферу обмена в Firefox через Google). Для Chrome вам нужно написать расширение.
В вашем расширении background_page есть заполнитель (IFrame)
на вашей веб-странице есть кнопки или ссылки, такие как «вырезать», «копировать» и «вставить». Также на вашей странице есть скрытый iframe paste_holder, чтобы вернуть текст, прочитанный background_page вашего расширения. В файле манифеста вашего расширения используйте следующий код:
manifest.json
"background_page": "mypaste_helper.html",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["mypaste_helper.js"],
"all_frames": true
}
],
"permissions": [
"clipboardRead",
"clipboardWrite",
"tabs"
]
mypaste_helper.js
получить ссылки на кнопки вырезания, копирования и копирования на странице
cutButton.addEventListener("click", function()
{
get selected content using window.getSelection()
pass that text to handleCut function in mypaste_helper.html
}, false);
copyButton.addEventListener("click", function()
{
get selected content using window.getSelection()
pass that text to handleCopy function in mypaste_helper.html
}, false);
pasteButton.addEventListener("click", function()
{
get content from handlePaste function in mypaste_helper.html
}, false);
в функции обратного вызова
получить содержимое, отправленное функцией background_page
установить innerHTML для документа frame.body фрейма paste_holder с полученным текстом.
mypaste_helper.html
handleCopy и handleCut идентичны
get reference to your iframe document.body as clipboardholder
set innerHTML of the clipboardholder.contentDocument.body with the data passed by mypaste_helper.js
capture selection through window.getSelection()
selection.selectAllChildren(clipboardholder);
document.execCommand('copy')
read contents of the clipboardholder
pass the text back to callback in mypaste_helper.js
handlePaste
get reference to your iframe document.body as clipboardholder
you may want to clear the contents of clipboardholder.contentDocument.body
capture selection through window.getSelection()
selection.selectAllChildren(clipboardholder);
document.execCommand('paste')
read contents of the clipboardholder
pass the text back to callback in mypaste_helper.js