| Autor | Zpráva | ||
|---|---|---|---|
| DarkMeni Profil |
#1 · Zasláno: 21. 12. 2011, 16:02:26
Zdravím, mám problém s nastavením kurzoru po vložení textu do textarei v IE, kurzor buď skočí za vložený text, nebo když byl nějaký text označený před tím, tak se neobjeví nikde, a po napsání dalšího znaku se předtím označený text a třeba bb kód vložený s ním vymaže. Ve Firefoxu to funguje, ale pro něj mam napsanou jinou větev podmínky.
function insertText(textarea, text, selected, bbopen, range){
var scrolltop = textarea.scrollTop;
var scrollheight = textarea.scrollHeight;
textarea.focus();
if(typeof document.selection != 'undefined' && document.selection.createRange){
//Pro IE
var selection = document.selection.createRange();
var start = end = text.length;
selection.text = text;
if(typeof range != 'undefined'){
selection.moveStart('character', start + text.indexOf(range));
selection.moveEnd('character', start + text.indexOf(range) + range.length);
}else{
if(selected == '' && typeof bbopen !== 'undefined'){
selection.move('character', start + bbopen.length);
}else{
selection.move('character', start + text.length);
}
}
range.select();
}else if(typeof textarea.selectionStart !== 'undefined'){
//Pro Firefox
var start = textarea.selectionStart, end = textarea.selectionEnd;
textarea.value = textarea.value.substr(0, start) + text + textarea.value.substr(end);
if(typeof range == 'undefined'){
if(selected == '' && typeof bbopen !== 'undefined'){
textarea.selectionStart = start + bbopen.length;
textarea.selectionEnd = start + bbopen.length;
}else{
textarea.selectionStart = start + text.length;
textarea.selectionEnd = start + text.length;
}
}else{
textarea.selectionStart = start + text.indexOf(range);
textarea.selectionEnd = start + text.indexOf(range) + range.length;
}
delete range;
}else{
//Kdyby nic nevyšlo
textarea.value += text;
}
textarea.scrollTop = scrolltop + (textarea.scrollHeight - scrollheight);
return true;
}Taky mě jen tak mimo zajímá (a nechci pro to zakládat další téma, protože se to tu někde řešilo, snad v sekci php, ale nevyřešilo) čím fungují živý chaty? Je to javascriptem nebo něčím jiným (třeba Javou nebo Flashem)? / Popřípadně existuje v js nějaká událost, která pozná, že se v databázi něco změnilo, kdyby jsem mu nějak řekl, aby to hlídal? |
||
|
Časová prodleva: 15 let
|
|||
0