Skip to content

Instantly share code, notes, and snippets.

@ifree
Created November 1, 2011 09:18
Show Gist options
  • Save ifree/1330206 to your computer and use it in GitHub Desktop.
Save ifree/1330206 to your computer and use it in GitHub Desktop.
getselection
function GetSel()
{
if (window.getSelection) return window.getSelection();
else if (document.getSelection) return document.getSelection();
else if (document.selection) return document.selection.createRange().text;
else return '';
}
@lilydjwg
Copy link

lilydjwg commented Nov 1, 2011

火狐下 window.getSelection() 返回的是一个对象哦,toString() 下或者用 document.getSelection() 才能得到字符串的。

@ifree
Copy link
Author

ifree commented Nov 1, 2011

就是一个对象,字符串相加就是调的toString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment