私はcontenteditabledivでユーザー選択を見つけるためにいくつかのコードを書いています、私はこのquirksmodeの記事から私のコードを取っています。
function findSelection(){
var userSelection;
if (window.getSelection) {userSelection = window.getSelection;}
else if (document.selection){userSelection = document.selection.createRange();} // For microsoft
if (userSelection.text){return userSelection.text} //for Microsoft
else {return userSelection}
}
ChromeとFirefoxでテストしていalert(userSelection)
ますが、関数内または関数外でalert(findSelection();)を実行すると、が返されますfunction getSelection() {[native code]}
。私がそうするならば、console.log(findSelection();)
それは私に与えますgetSelection()
。私が間違ったことはありますか?