前提・実現したいこと
Google拡張機能を開発しています。
選択中の部分のコードをコピペするものを作りたいです。
発生している問題・エラーメッセージ
テキストは取得できるが、タグ付きでほしい。
該当のソースコード
js
1//コンテクストメニュー 右クリック時に出る表示のやつ 2chrome.contextMenus.create({ 3 "title" : "copy", 4 "type" : "normal", 5 "contexts" : ["selection"], 6 "onclick" : copytext() 7}); 8 9//選択中の文字列を取得 10function copytext(info,tab){ 11 return function(info,tab){ 12 var selection_text = info.selectionText; 13 saveToClipboard(selection_text); //取得した文字列をクリップボードにコピーする関数に送る 14 } 15} 16 17//選択中文字列をクリップボードに入れる 18function saveToClipboard(str) { 19 var textArea = document.createElement("textarea"); 20 document.body.appendChild(textArea); 21 textArea.value = str; 22 textArea.select(); 23 document.execCommand("copy"); 24 document.body.removeChild(textArea); 25 } 26ソースコード
タグ付きで取得するにはどうすればよいのでしょうか。
あなたの回答
tips
プレビュー