В IE это сделать довольно безболезненно. Для Firefox вам необходимо обновить users.js и / или prefs.js (вы можете использовать Google для доступа к буферу обмена в Firefox). Для 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 фрейма paste_holder document.body с полученным текстом.
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
person
Surya Upadhyayula
schedule
26.09.2011