Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/479.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript从网页中获取单击或选择的文本?_Javascript_Jquery_Google Chrome Extension_Gettext - Fatal编程技术网

如何使用javascript从网页中获取单击或选择的文本?

如何使用javascript从网页中获取单击或选择的文本?,javascript,jquery,google-chrome-extension,gettext,Javascript,Jquery,Google Chrome Extension,Gettext,如何使用javascript从网页中获取单击或选定的文本 如何获取手机号码或电子邮件等特定文本这应该适合您: const getSelectionText=()=>{ 让文本=”; if(window.getSelection){ text=window.getSelection().toString(); }else if(document.selection&&document.selection.type!=“控制”){ text=document.selection.createRan

如何使用javascript从网页中获取单击或选定的文本


如何获取手机号码或电子邮件等特定文本这应该适合您:

const getSelectionText=()=>{
让文本=”;
if(window.getSelection){
text=window.getSelection().toString();
}else if(document.selection&&document.selection.type!=“控制”){
text=document.selection.createRange().text;
}
返回文本;

}
请向我们展示您的html和代码。没有它真的很难给你一个好的答案