How can I get the selected HTML source code?
This code gets the selected text. I would like to get the HTML source code or the ID of selected HTML element.
This code gets the selected text. I would like to get the HTML source code or the ID of selected HTML element.
var selection = "";
if(editorInstance.EditorDocument.selection != null) {
selection = "value1 "+editorInstance.EditorDocument.selection.createRange().text;
}
else {
selection = "value2 "+editorInstance.EditorWindow.getSelection();
}
Re: get selected HTML Source Code
Re: get selected HTML Source Code
Thanks in advance.
Re: get selected HTML Source Code
// get HTML from selection function getSelectionHTML(selection) { var range = (document.all ? selection.createRange() : selection.getRangeAt(selection.rangeCount - 1).cloneRange()); if (document.all) { return range.htmlText; } else { var clonedSelection = range.cloneContents(); var div = document.createElement('div'); div.appendChild(clonedSelection); return div.innerHTML; } }Call the function like this
function FCKeditor_OnComplete( editorInstance ) { var selection = (editorInstance.EditorWindow.getSelection ? editorInstance.EditorWindow.getSelection() : editorInstance.EditorDocument.selection); alert(getSelectionHTML(selection)) ; }Re: get selected HTML Source Code
Re: get selected HTML Source Code
Re: get selected HTML Source Code
I tried modifying the code to match the new fangled ways:
function getSelectionHTML(selection) { var range = (document.all ? selection.getNative().createRange() : selection.getRanges()[selection.getRanges().length - 1].clone()); if (document.all) return range.htmlText; else return $("<div></div>").append(range.cloneContents()).html(); }It does not like the contents for the range object. Get: DOM Exception: HIERARCHY_REQUEST_ERR (3) on the append.
Have you worked on this problem with the new CKeditor?