Results 1 to 2 of 2

Thread: Great HTML Editor Javascript Code

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Talking Great HTML Editor Javascript Code

    Just place this into a form and voila!!!!
    Code:
    <html>
    <head>
    <title>HTML Editor</title>
    <script language="JavaScript">
    
      function Init()
      {
        iView.document.designMode = 'On';
        setTimeout("populate()",500)
      }
      
      function populate(){
    	iView.document.body.innerHTML = window.opener.inputForm.txtDesc.value
    	iView.document.body.focus()
      }
      
      function selOn(ctrl)
      {
    	ctrl.style.borderColor = '#000000';
    	ctrl.style.backgroundColor = '#B5BED6';
    	ctrl.style.cursor = 'hand';	
      }
      
      function selOff(ctrl)
      {
    	ctrl.style.borderColor = '#D6D3CE';  
    	ctrl.style.backgroundColor = '#D6D3CE';
      }
      
      function selDown(ctrl)
      {
    	ctrl.style.backgroundColor = '#8492B5';
      }
      
      function selUp(ctrl)
      {
        ctrl.style.backgroundColor = '#B5BED6';
      }
        
      function doBold()
      {
    	iView.document.execCommand('bold', false, null);
      }
    
      function doItalic()
      {
    	iView.document.execCommand('italic', false, null);
      }
    
      function doUnderline()
      {
    	iView.document.execCommand('underline', false, null);
      }
      
      function doLeft()
      {
        iView.document.execCommand('justifyleft', false, null);
      }
    
      function doCenter()
      {
        iView.document.execCommand('justifycenter', false, null);
      }
    
      function doRight()
      {
        iView.document.execCommand('justifyright', false, null);
      }
    
      function doOrdList()
      {
        iView.document.execCommand('insertorderedlist', false, null);
      }
    
      function doBulList()
      {
        iView.document.execCommand('insertunorderedlist', false, null);
      }
      
      function doForeCol()
      {
        var fCol = prompt('Enter font color', '');
        
        if(fCol != null)
          iView.document.execCommand('forecolor', false, fCol);
      }
    
      function doLink()
      {
        iView.document.execCommand('createlink');
      }
      
      function doFont(fName)
      {
        if(fName != '')
          iView.document.execCommand('fontname', false, fName);
      }
      
      function doSize(fSize)
      {
        if(fSize != '')
          iView.document.execCommand('fontsize', false, fSize);
      }   
      
      var didSave = false
      
      function saveAndClose()
      { 
    		didSave = true
    		iHTML = iView.document.body.innerHTML 
    		
    		myString = new String(iHTML)
    		rExp = /<P align=left>/gi;
    		newString = new String("<DIV align=left>")
    		iHTML = myString.replace(rExp, newString)
    		iView.document.body.innerHTML = iHTML		
    
    		myString = new String(iHTML)
    		rExp = /<P align=center>/gi;
    		newString = new String("<DIV align=center>")
    		iHTML = myString.replace(rExp, newString)
    		iView.document.body.innerHTML = iHTML		
    
    		myString = new String(iHTML)
    		rExp = /<P align=right>/gi;
    		newString = new String("<DIV align=right>")
    		iHTML = myString.replace(rExp, newString)
    		iView.document.body.innerHTML = iHTML
    		
    		myString = new String(iHTML)
    		rExp = /<P>/gi;
    		newString = new String("<DIV>")
    		iHTML = myString.replace(rExp, newString)
    		iView.document.body.innerHTML = iHTML
    		
    		myString = new String(iHTML)
    		rExp = /<[/]P>/gi;
    		newString = new String("</DIV>")
    		iHTML = myString.replace(rExp, newString)								
    		
    		window.opener.inputForm.txtDesc.value = iHTML
    		window.close() 
      }
     
      function saveIt(){
    	 if (!didSave && iView.document.body.innerHTML != ""){
    		 if(confirm("Do you want to save?")){
    			 saveAndClose() 		
    		 }
    	 }
      }
    </script>
    <style TYPE="text/css">
    	body	{position: absolute; top: 0; left: 0; margin: 0; padding: 0  }
    
      .butClass
      {    
        border: 1px solid;
        border-color: #D6D3CE;
      }
      
      .tdClass
      {
        padding-left: 3px;
        padding-top:3px;
      }
    
    </style>
    
    </head>
    
    <body onLoad="Init()" onBeforeUnload="saveIt()">
    	<table id="tblCtrls" width="415px" height="30px" border="0" cellspacing="0" cellpadding="0" bgcolor="#D6D3CE">	
    	<tr>
    		<td class="tdClass">
    			<img class="butClass" alt="Save and Close" src="images/htmleditor/save_and_close.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="saveAndClose()" width="100" height="22">
    		
    			<img alt="Bold" class="butClass" src="images/htmleditor/bold.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doBold()" width="23" height="22">
    			<img alt="Italic" class="butClass" src="images/htmleditor/italic.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doItalic()" width="23" height="22">
    			<img alt="Underline" class="butClass" src="images/htmleditor/underline.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doUnderline()" width="23" height="21">
    			
    			<img alt="Left" class="butClass" src="images/htmleditor/left.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doLeft()" width="23" height="22">
    			<img alt="Center" class="butClass" src="images/htmleditor/center.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doCenter()" width="23" height="22">
    			<img alt="Right" class="butClass" src="images/htmleditor/right.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doRight()" width="23" height="22">
    						
    			<img alt="Ordered List" class="butClass" src="images/htmleditor/ordlist.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doOrdList()" width="23" height="22">
    			<img alt="Bulleted List" class="butClass" src="images/htmleditor/bullist.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doBulList()" width="23" height="22">
    			
    			<img alt="Text Color" class="butClass" src="images/htmleditor/forecol.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doForeCol()" width="23" height="22">			
    			<img alt="Hyperlink" class="butClass" src="images/htmleditor/link.gif" onMouseOver="selOn(this)" onMouseOut="selOff(this)" onMouseDown="selDown(this)" onMouseUp="selUp(this)" onClick="doLink()" width="23" height="22">			
    		</td>
    	</tr>
    	</table>
    	<iframe id="iView" style="width: 415px; height:205px"></iframe>
    
        <table width="415px" height="30px" border="0" cellspacing="0" cellpadding="0" bgcolor="#D6D3CE">	
        <tr>
    		<td class="tdClass" colspan="1" width="50%">
    		  <select name="selFont" onChange="doFont(this.options[this.selectedIndex].value)">
    		    <option value="">-- Font --</option>
    		    <option value="Arial">Arial</option>
    		    <option value="Courier">Courier</option>
    		    <option value="Sans Serif">Sans Serif</option>
    		    <option value="Tahoma">Tahoma</option>
    		    <option value="Verdana">Verdana</option>
    		    <option value="Wingdings">Wingdings</option>
    		  </select>
    		  <select name="selSize" onChange="doSize(this.options[this.selectedIndex].value)">
    		    <option value="">-- Size --</option>
    		    <option value="1">Very Small</option>
    		    <option value="2">Small</option>
    		    <option value="3">Medium</option>
    		    <option value="4">Large</option>
    		    <option value="5">Larger</option>
    		    <option value="6">Very Large</option>
    		  </select>
    		</td>
    		<td class="tdClass" colspan="1" width="50%" align="left">
    		</td>
        </tr>
        </table>
    </body>
    </html>

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Whoohoo... a project that does absolutely nothing. It is just loaded with errors.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width