Get parent element of caret in iframe design mode
问题 I want to know what is the parent element of caret in an iframe with designMode = 'on' . The reason is that want to know if currently user is typing in a p tag. 回答1: Here's a function to do this, adapted from an answer to a similar question: function getSelectionBoundaryElement(win, isStart) { var range, sel, container = null; var doc = win.document; if (doc.selection) { // IE branch range = doc.selection.createRange(); range.collapse(isStart); return range.parentElement(); } else if (win