選擇我有這個功能清除在Firefox
function smth() {
var container = null;
var newContainer = null;
if (window.getSelection) { // all browsers, except IE before version 9
alert("first if");
var selectionRange = window.getSelection();
if (selectionRange.rangeCount > 0) {
var range = selectionRange.getRangeAt(0);
container = range.commonAncestorContainer;
newContainer = container;
}
}
else {
if (document.selection) { // Internet Explorer
alert("second if");
var textRange = document.selection.createRange();
container = textRange.parentElement();
}
}
if (newContainer) {
return newContainer.nodeName;
}
else {
alert("Container object for the selection is not available!");
}
}
後,現在我做什麼,我需要選擇我需要明確它做。我嘗試了一些沒有用的東西,有什麼想法?
document.selection.clear()
這沒有工作。
謝謝你,它有助於預期例如TinyMCE的編輯器窗口中(iframe中實際上) – Ovi 2011-05-31 12:14:37
將無法工作。您將需要使用:tinymce.activeEditor.selection.collapse(); – Recoil 2013-12-02 06:16:57
「對於有問題的瀏覽器」不再是這種情況。後面的選項適用於所有瀏覽器,包括最新版本的IE。 (假設你的意思是IE瀏覽器「有問題」。) – Porschiey 2014-11-07 16:47:26