Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> selection
a79rtur
post
Post #1





Grupa: Zarejestrowani
Postów: 331
Pomógł: 1
Dołączył: 23.05.2004
Skąd: Tarnów/Londyn

Ostrzeżenie: (0%)
-----


czesc, mam nastepujacy problem:
selection to zaznaczony tekst w polu pewnym
jak dam alert(selection); to zwraca mi część ciągu która jest zaznaczona
jak mam zrobic zeby tą część pogrubiło i zapisalo do zmiennej pogrubione ?
próbuje:

oRTE.document.selection=('<b>' + selection + '</b>');

ale cos nie robi (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
a79rtur
post
Post #2





Grupa: Zarejestrowani
Postów: 331
Pomógł: 1
Dołączył: 23.05.2004
Skąd: Tarnów/Londyn

Ostrzeżenie: (0%)
-----


ok. cala funkcja

Kod
//Function to format text in the text box
function FormatText(rte, command, option) {
    var oRTE;
    if (document.all) {
  oRTE = frames[rte];
  
  //get current selected range
  var selection = oRTE.document.selection;
  if (selection != null) {
     rng = selection.createRange();
  }
    } else {
  oRTE = document.getElementById(rte).contentWindow;
  
  //get currently selected range
  var selection = oRTE.getSelection();
  rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    }
    
    try {
  if ((command == "forecolor") || (command == "hilitecolor")) {
     //save current values
     parent.command = command;
     currentRTE = rte;
    
     //position and show color palette
     buttonElement = document.getElementById(command + '_' + rte);
     // Ernst de Moor: Fix the amount of digging parents up, in case the RTE editor itself is displayed in a div.
     document.getElementById('cp' + rte).style.left = getOffsetLeft(buttonElement, 4) + "px";
     document.getElementById('cp' + rte).style.top = (getOffsetTop(buttonElement, 4) + buttonElement.offsetHeight + 4) + "px";
     if (document.getElementById('cp' + rte).style.visibility == "hidden") {
    document.getElementById('cp' + rte).style.visibility = "visible";
    document.getElementById('cp' + rte).style.display = "inline";
     } else {
    document.getElementById('cp' + rte).style.visibility = "hidden";
    document.getElementById('cp' + rte).style.display = "none";
     }
  } else if (command == "createlink") {
     var szURL = prompt("Wpisz adres strony:", "http://");
     try {
    //ignore error for blank urls
    oRTE.document.execCommand("Unlink", false, null);
    oRTE.document.execCommand("CreateLink", false, szURL);
     } catch (e) {
    //do nothing
     }
    
  } else if (command == "createemail") {
     var szEMAIL = prompt("Wpisz adres email:", "mailto:");
     try {
    //ignore error for blank urls
    oRTE.document.execCommand("Unlink", false, null);
    oRTE.document.execCommand("CreateLink", false, szEMAIL);
     } catch (e) {
    //do nothing
     }
    
  } else if (command == "uzyjstylu") {
    
//////////////////////////////////////////////////////////////////////////////////////////
     oRTE.document.selection.createRange().text.fontsize("20");
/////////////////////////////////////////////////////////////////////////////////////////  
    
  } else if (command == "usunstyl") {
     oRTE.focus();
     //oRTE.document.getSelection().style.visibility = "hidden";

         var html=oRTE.document.body.innerHTML;
         var html_male=html.toLowerCase();
        
         start_div_open = html_male.indexOf( "\<div style" ); //zwraca poczatek otwarcia div'a
         //alert(start_div_open);
        
         end_div_open = html_male.indexOf( "\"\>", start_div_open);
        
         end_div_open += 2;
         start_div_close = html_male.lastIndexOf("</div>");
      
         //alert(start_div_close);
         if (start_div_open!=-1 && start_div_close!=-1)
         {
          html=html.substring(end_div_open, start_div_close);
          oRTE.document.body.innerHTML=html;
         }
        
      oRTE.focus();
    
  } else {
     oRTE.focus();
        oRTE.document.execCommand(command, false, option);
     oRTE.focus();
  }
    } catch (e) {
  alert(e);
    }
}
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.12.2025 - 21:19