Ejemplos en Javascript

Editor de textos

Este script genera una especie de editor de textos que visualiza el texto en una ventana independiente.

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>



</HEAD>

<BODY bgcolor="white">

<Script language="JavaScript">


myColor = new Array (1) ;
myColor[0] = "#FF0000" ;
myColor[1] = "#CC0099" ;
myColor[2] = "#990099" ;
myColor[3] = "#CC00FF" ;
myColor[4] = "#330099" ;
myColor[5] = "#006699" ;
myColor[6] = "#33FF99" ;
myColor[7] = "#336600" ;
myColor[8] = "#666000" ;
myColor[9] = "#996600" ;
myColor[10] = "#FF9900" ;
myColor[11] = "#FFCC33" ;
myColor[12] = "#FFFF00" ;
myColor[13] = "#FF9966" ;

var b = 0 ;

 function morefun () {
   var backColor = document.myform.myselect[document.myform.myselect.selectedIndex].value ;
   mywin = newwin = window.open("", "mywin","toolbar=no,directories=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=no,location=no,,");
   mystring = document.myform.myarea.value ;
if (document.myform.isHTML.status==false) {
   mywin.document.writeln("<HTML><HEAD>") ;
   mywin.document.writeln("<TITLE>Somewhere over the rainbow....</TITLE>") ;



   }
var i = 0 ;
  while (i != mystring.length) {
   a = mystring.substring(i, i+1) ;
   if (a=="<") {
     z = i ;
      while (a != ">") {
        z ++
        a = mystring.substring(z, z+1) ;
        }
     a = mystring.substring(i, z+1) ;
      mywin.document.writeln(a) ;
     i = z + 1;
    }
  else if (a == " "|| a == "" || a == "  ") {
    mywin.document.write(a) ;
    i++ ;
          }
  else {
 
    if (b>13) {
      b = 0 ;
      }
   c = myColor[b] ;
   mywin.document.write(a.fontcolor(c)) ;
   b++ ;
   i++ ;
  }
}
if (document.myform.isHTML.status==false) {
 mywin.document.writeln('') ;
 mywin.document.writeln('') ;
 }
mywin.document.close() ;
}
</SCRIPT>

<P align="center"><CENTER><FORM name="myform">
HTML Source <input type=checkbox name="isHTML">
<select name="myselect">
<option value="black">Black Background
<option value="white">White Background
</select><BR>
<TEXTAREA NAME="myarea" ROWS="10" COLS="30">
 

Ventanas