任意の文字列をクリップボードにコピー
スクリプト内で実行すれば貴方のクリップボードに( ᐛ) パァが入る。
function copyToClipBoard() { var anyText= "( ᐛ) パァ"; var textBox = document.createElement("textarea"); textBox.setAttribute("id", "target"); textBox.setAttribute("type", "hidden"); textBox.textContent = anyText; document.body.appendChild(textBox); textBox.select(); document.execCommand('copy'); document.body.removeChild(textBox); }
以下のコードでブックマークレットを作るといつでもどこでもクリックひとつで( ᐛ) パァをあなたの手元に用意することが出来る。
javascript: var anyText= "( ᐛ) パァ"; var textBox = document.createElement("textarea"); textBox.setAttribute("id", "target"); textBox.setAttribute("type", "hidden"); textBox.textContent = anyText; document.body.appendChild(textBox); textBox.select(); document.execCommand('copy'); document.body.removeChild(textBox);
JSを追加で読み込む
ブックマークレットとか作るときとかにたまに使う。
function readJS() { var script=document.createElement('script'); script.setAttribute("src", "https://hoge.js"); script.setAttribute("src", "./foo.js"); document.body.appendChild(script); }