【问题标题】:How to create a "Form pop up box" above a highlighted word when rightclicked in chrome?在chrome中右键单击时,如何在突出显示的单词上方创建一个“表单弹出框”?
【发布时间】:2025-12-21 19:55:06
【问题描述】:
【问题讨论】:
标签:
javascript
jquery
html
google-chrome
google-chrome-extension
【解决方案2】:
您需要使用以下内容创建内容脚本:
function getSelectedText() {
var text = "";
if (typeof window.getSelection != "undefined") {
text = window.getSelection().toString();
} else if (typeof document.selection != "undefined" && document.selection.type == "Text") {
text = document.selection.createRange().text;
}
return text;
}
document.addEventListener('mouseup', function(e) {
var selectedText = getSelectedText();
if (selectedText) {
alert("Selected text: " + selectedText);
}
}, false);