inserting a special char
2006/04/11 21:39
Viewed 6759 times
Replies: 1/2
well. my problem is that i created a new function for this, it works great on windows firefox and ie, but firefox from linux has a little bug and i cant find out how to solve this, if i start inserting characters, i cant delete them, unless a press any key, am i doing something wrong? this is the function that im using.. HTMLArea.prototype.insertChar = function(car) { var sel = this._getSelection(); var range = this._createRange(sel); if (HTMLArea.is_ie) { range.pasteHTML(car); } else { var range2 = range.cloneRange(); var innerHTML = this.getHTML(); alert(innerHTML); //Fix for Firefox 1.5 . if(innerHTML == " "){ sel = this._getSelection(); sel.removeAllRanges(); range = this._createRange(); range.selectNodeContents(this._doc.body); sel.addRange(range); } var div = this._doc.createTextNode(entityDecode(car)); // Insert text at cursor position sel.removeAllRanges(); range.deleteContents(); range.insertNode(div); // Move the cursor to the end of text range2.selectNode(div); range2.collapse(false); sel.removeAllRanges(); sel.addRange(range2); } }; its weird cause it works in firefox for windows, it deletes everything correctly, but in linux it acts a little different :S hope some can point me out what im doing wrong, thnxs in advance.
Re: inserting a special char
2006/04/11 21:42
Viewed 10345 times
Replies: 1/1

function entityDecode(s) {
var e = document.createElement("div");
e.innerHTML = s;
return e.innerHTML;
}

//Agrega un caracter especial en el textarea.
HTMLArea.prototype.insertChar = function(car) {
var sel = this._getSelection();
var range = this._createRange(sel);
if (HTMLArea.is_ie) {
range.pasteHTML(car);
} else {
var range2 = range.cloneRange();
var innerHTML = this.getHTML();
alert(innerHTML);
//Fix para Firefox 1.5 ya que si se inserta un caracter especial
//sin que tenga foco el html area, no lo pone correctamente en
//la primera posicion.
if(innerHTML == " "){
sel = this._getSelection();
sel.removeAllRanges();
range = this._createRange();
range.selectNodeContents(this._doc.body);
sel.addRange(range);
}
if(innerHTML.indexOf('<') == 0){
sel = this._getSelection();
sel.removeAllRanges();
range = this._createRange();
range.selectNodeContents(this._doc.body);
sel.addRange(range);
}

// construct a new document fragment with the given HTML
//var fragment = this._doc.createDocumentFragment();

var div = this._doc.createTextNode(entityDecode(car));
//var div = this._doc.createTextNode(car);
//div.innerHTML = car;
//alert(div.innerHTML);
// Insert text at cursor position
sel.removeAllRanges();
range.deleteContents();
range.insertNode(div);
// Move the cursor to the end of text
range2.selectNode(div);
range2.collapse(false);
sel.removeAllRanges();
sel.addRange(range2);
}
};

last
Re[2]: inserting a special char
2006/04/13 00:05
Viewed 14072 times
Replies: 0/0

what i believe is happening is that firefox "thinks" the htmlarea is empty, thats why i cant delete the characters that i insert..... is there a way to create an event like keydown..? so firefox thinks that someone pressed a key and inserted a character...

last
Google