function getSelectedContents(){
if (window.getSelection) { //chrome,firefox,opera
var range=window.getSelection().getRangeAt(0);
var container = document_createElement_x_x_x_x('div');
container.a(range.cloneContents());
return container.innerHTML;
//return window.getSelection(); //只复制文本
}
else if (document.getSelection) { //其他
var range=window.getSelection().getRangeAt(0);
var container = document_createElement_x_x_x_x('div');
container.a(range.cloneContents());
return container.innerHTML;
//return document.getSelection(); //只复制文本
}
else if (document.selection) { //IE特有的
return document.selection.createRange().htmlText;
//return document.selection.createRange().text; //只复制文本
}
}
js获取网页选中部分的内容,包含html代码
最新推荐文章于 2024-04-13 08:52:10 发布