我想寫一個JavaScript腳本添加到添加按鈕後的按鈕的greasemonkey。該按鈕的onClick應該將父母元素文本複製到鍵盤。我看到過很多這樣的副本已選定文本複製到剪貼板像這樣的例子:Greasemonkey JavaScript複製到剪貼板按鈕
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function copyit(theField) {
var selectedText = document.selection;
if (selectedText.type == 'Text') {
var newRange = selectedText.createRange();
theField.focus();
theField.value = newRange.text;
} else {
alert('Alert: Select The text in the textarea then click on this button');
}
}
// End -->
</script>
<input onclick="copyit(this.form.text_select)" type="button" value="Click Here to Copy the Highlighted Text" name="copy_button">
找到here。
我也發現你可以在輸入元素中選擇文本。我嘗試將兩種技術以及許多其他方法結合起來,但還沒有可行的解決方案。我甚至不知道爲什麼上面的代碼複製到剪貼板。有沒有人有解決這個問題?
另請注意:https://developer.mozilla.org/en/Using_the_Clipboard – javamonkey79 2008-12-25 02:40:29