user1405631
user1405631

Reputation:

Ie doesnt like range

I have a WYSIWYG editor working in all browsers except IE (all versions). I have a problem with the function below:

function tag(tag) {
    var range = window.frames['textEditor'].getSelection().getRangeAt(0);
    var newNode = document.createElement(tag);
    range.surroundContents(newNode);
}

Any ideas on how to fix this?

Upvotes: 0

Views: 452

Answers (3)

user1405631
user1405631

Reputation:

i Have it working in all browsers now if anyone needs the script i will post it bellow

   function changeHeading(heading) {

  if($.browser.msie && $.browser.version == 7 || $.browser.version == 8)
  {
    theSelection = window.frames['textEditor'].document.selection.createRange().htmlText;
    window.frames['textEditor'].document.selection.createRange().pasteHTML("<"+heading+">"+theSelection+"</"+heading+">")
    $("#textEditor").contents().find(heading).unwrap();
  }

  else {
    var needle =window.frames['textEditor'].getSelection().getRangeAt(0);
    var haystack = $('#textEditor').contents().find("body").text();
    var newText = haystack.replace(needle,"<"+heading+">"+needle+"</"+heading+">");
    $('#textEditor').contents().find("body").html(newText);
    $("#textEditor").contents().find(heading).unwrap();
}
}

Thanks for the help

Upvotes: 0

Tim Down
Tim Down

Reputation: 324657

IE < 9 doesn't have support for standard DOM Range and Selection. For an implementation of these APIs that works in these and all major browsers, you could use my Rangy library.

As an aside, using the surroundContents() method of a range will only work when the range starts and ends in the same node or children of the same node. For example, it will not work for a range such as the following (with range boundaries denoted by square brackets):

One |two <b>three| four</b>

To style ranges like this you'll need a more subtle approach.

Upvotes: 1

Jordan
Jordan

Reputation: 32552

IE doesn't support range, because it's a big baby. However, it will do what you want, but with separate logic. Check out the Quirksmode Range Page for info on how to whip IE into shape.

Upvotes: 1

Related Questions