javascript - 选中文本进入右键
问题描述
是否有另一种方法来突出显示文本(保留换行符)?
var newProspect = function(string){
console.log(string.selectionText);
};
chrome.contextMenus.create({
title: "New Prospect",
contexts:["all"],
onclick: newProspect
});
解决方案
var newProspect = function(string){
chrome.tabs.executeScript(
{
code: "window.getSelection().toString(); ",
},
function (selection) {
var selectionText = selection[0]
}
);
};
chrome.contextMenus.create({
title: "New Prospect",
contexts: ["selection"],
onclick: newProspect,
});
推荐阅读
- android - 如何限制 Framelayout 在屏幕上占用的空间量?
- python - 当我使用常规运行时间(分钟)时,我的错误是 25,但是当我记录运行时日志(使其正常)时,我的错误是 0.3?
- c# - 我的 C# 控制器中的参数从 AJAX 调用读取为 null
- sql - 如何在选择查询中不显示项目?
- powerbi - 如何在 PowerBI 中创建一个 x 轴和两个平行 y 轴的条形图
- ios - 使用 sharedApplication openURL 方法在 Safari 中使用 POST 方法打开 URL
- reactjs - 开玩笑遇到了一个意外的令牌-看起来无法转换 jsx 元素
- c++ - 如何使用面板在穿山甲中显示 2D 图形
- azure-cosmosdb - Azure cosmosDB 不会删除 TTL 过期的文档
- ruby-on-rails - 是 否 Rails 中的 check_box_tag 无法正常工作