javascript Эмуляция клика и вставки текста из -- скопировать строку в буфер обмена ctrl+c, ctrl+v (скопировать clipboard)
Primary tabs
Задача -- загнать текст в буфер и добавить его в поле.
ОБщая идея:
document.querySelector("body").addEventListener("click", copy);
function copy()
{
// начало копирования строки в буфер
var dummy = document.createElement("input");
/* Add it to the document */
document.body.appendChild(dummy);
/*/ Set its ID */
dummy.setAttribute("id", "dummy_id");
/*/ Output the array into it */
document.getElementById("dummy_id").value='rufromru@yandex.ru';
/*/ Select it */
dummy.select();
document.execCommand("copy");
// окончаник копирования строки
// клик по элементу ввода
document.getElementsByClassName("mail-Compose-Field-Input")[0].childNodes[2].click()
// выполняем Ctrl+V
document.execCommand("paste");
}
-- приходится делать клик вручную, не всякий браузер разрешит:
Полезно почитать:
- https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard
- https://stackoverflow.com/questions/41094318/firefox-document-execcommand-cut-copy-was-denied-because-it-was-not-calle
- Log in to post comments
- 7004 reads