I'm having to debug a WYSIWYYG javascript based HTML editor that is failing in IE8. It's only designed for use in IE so that should simplify the solution. Here's the existing code that is failing:
function isAllowed() {
var sel
var obj
sel = foo.document.selection
if (sel.type != "Control")
{
obj = sel.createRange().parentElement()
} else {
obj = sel.createRange()(0)
}
if (obj.isContentEditable) {
foo.focus()
return true
} else {
return false
}
}
Essentially what is happening is that if you select some text and click say the 'insert image' button it first runs this isAllowed function to see if the text you've selected is editable (i.e. within the iframe that is content editable). This seems to be breaking down in IE8 at at either document.selection or createRange(). The problem is that when you don't select any text with your mouse but just click somewhere in the editable region sel.createRange().parentElement() seems to return an element outside of the iframe and it's thus not ContentEditable and the function returns false.
I'm wondering if anyone could shed any insight on to what has changed in IE8's implementation of selections and ranges that would cause this behaviour?