<script>
function getSel()
{
var txt = '';
var foundIn = '';
if(window.getSelection)
{
txt = window.getSelection();
foundIn = 'window.getSelection()';
}else if(document.getSelection)
{
txt = document.getSelection();
foundIn = 'document.getSelection()';
}else if(document.selection)
{
txt = document.selection.createRange().text;
foundIn = 'document.selection.createRange()';
}else
return;
document.forms[0].selectedtext.value = 'Found in: ' + foundIn + '\n' + txt;
}
</script>
<form>
<textarea name="selectedtext" rows="5" cols="50">
</textarea><br>
<input type="button" value="Getselection" onmousedown="getSel()">
</form>
以上的代码可以捕获到选中的网页中的纯文本内容(不含HTML标签)
如果想获得包含html的内容,将document.selection.createRange().text改成document.selection.createRange().htmlText
[Javascript]document.getSelection,document.selecti
相关推荐
- vs出现错误,无法启动 Visual Studio。StreamJsonRpc.ConnectionLostException:在请求完成之前,与远程的JSON-RPC连接已丢失_客服专区-CSDN问答
- 【转】Chrome内核浏览器打开网页报 错误代码: ERR_TIMED_OUT - m_lm的个人空间 - OSCHINA - 中文开源技术交流社区
- ASP.NET Core WebApi配置跨域_asp.net core webapi 跨域-CSDN博客
- C# 怎么用OpenCVSharp4实现图片表格识别
- ChatGPT 本地部署及搭建_孟郎郎的博客-CSDN博客
- Cursor 全自动代码生成器?你还没用过?接下来我就来介绍智能 AI 代码生成工具 Cursor 安装和使用 - 掘金
- 【Windows】文件夹被占用删除不掉_Energet!c的博客-CSDN博客
- docfile已损坏 docfile has been corrupted visual studio 2022