Newsgroup: it.comp.lang.javascript
Titolo: Scriptino x Forum

Ciao
Scusate l'ignoranza, domanda banale:
sto realizzando un forum per un sitarello e vorrei implementare la
formattazione del testo dei messaggi che si inseriscono.
Premendo per esempio un pulsante in cui c'è scritto "grassetto" si dovrebbe
aprire una finestrella java in cui si immette il testo da ingrassettare e si
invia al campo di testo del form della pagina principale (racchiuso da
opportuni tag la cui traduzione in html ho già implementato). Allo stesso
tempo, una volta premuto il tasto di "inserimento", tale finestrella si
chiude. Come si fa?
Dove trovo scriptini stupidi di questo genere? (non ne ho trovati su
www.html.it
)
grazie
--
saku

ciao, il metodo migliore per fare quello che dici è usare il comando:
execcommand. L'elenco delle cose che puoi fare lo trovi qui
http://msdn.microsoft.com/workshop/author/dhtml/reference/commandids.asp
Ricordati che il tutto funziona solo su explorer e non è un oggetto java,
ma una "semplice" funziona integrata in explorer.
Ciao
Qui di seguito ti metto un'esempio. Ariciao
<html>
<head>
<title></title>
<script  language="JavaScript">
// -->
</script>
<style type="text/css">
<!--
text {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
12px; color: #000000;}
bold {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
12px; color: #000000; font-weight: bold;}
heading {font-family: Arial, Helvetica, sans-serif; font-size: 18px;
color: #000000;}
lgText {font-family: Arial, Helvetica, sans-serif; font-size: 15px;
color: #000000; font-weight: bold;}
tHeading {font-family: Arial, Helvetica, sans-serif; font-size: 12px;
color: #000000; font-weight: bold;}
tiHeading {font-family: Arial, Helvetica, sans-serif; font-size: 12px;
color: #000000; font-weight: bold;}
a {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;
color: white;}
a:hover {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
12px; color: white;}
a:visited {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:
12px; color: white;}
a:visited:hover {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px; color: white;}
-->
</style>
<script language="JavaScript">
function status_bott(imag){
var img;
img=imag.src;
var scelta;
// prendo quello che c'è dopo l'underscore (on/off.gif)
scelta=img.substr(img.lastIndexOf("_")+1);
var src_com;
// prendo il percorso dell'immagine fino all'unders. (quindi escludo
on/off .gif)
src_com=img.substring(0,img.lastIndexOf("_")+1);
if (scelta=="off.gif"){
imag.src=src_com+"on.gif";
}
else{
imag.src=src_com+"off.gif";
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" background="" marginheight="0"
marginwidth="0" topmargin="0" leftmargin="0">
<div align="center"><span class="heading">Scrivi Messaggio</span><br>
<script  language="JavaScript">
<!-- Hide from older browsers...
//Function to format text in the text box
function FormatText(command, option){
	frames.message.focus();
  	frames.message.document.execCommand(command, false, option);
  	frames.message.focus();
}
function ester(){
	frames.message.focus();
  	window.external.AddFavorite("
http://www.olimpiamilano.com
",
"olimpianelcuore");
  	frames.message.focus();
}
//Function to add image
function AddImage(){	
	imagePath = prompt('Inserisci l\'URL riferito all\'immagine',
'http://');				
 
	if ((imagePath != null) && (imagePath != "")){	
		frames.message.focus(); 				
		frames.message.document.execCommand('InsertImage', false, imagePath);
	}
	frames.message.focus();			
}
//Function to clear form
function ResetForm(){
	if (window.confirm('Sei sicuro di voler resettare il form?')){
		frames.message.focus();
	 	frames.message.document.body.innerHTML = ''; 
	 	return true;
	 } 
	 return false;		
}
//Function to open pop up window
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}
// -->
</script>
<form method="post" name="frmAddMessage"
action="post_message.asp?PagePosition=1" onSubmit="return CheckForm();"
onReset="return ResetForm();">
 <table width="620" border="0" cellspacing="0" cellpadding="1"
bgcolor="#666666" height="230" align="center">
  <tr> 
   <td height="66" width="967"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"
align="center" bgcolor="#5C8FC7" background="" height="201">
     <tr> 
      <td height="199"> 
       <table width="100%" border="0" align="center" height="233"
cellpadding="2" cellspacing="0">
        <tr> 
         <td colspan="2" height="30" class="text" align="left">*Indica
campi obbligatori</td>
        </tr>
        <tr> 
         <td valign="bottom" align="right" height="22" width="15%"><span
class="text"> </span></td>
         <td height="22" width="85%" valign="bottom"> 
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
           <tr> 
            <td> 
             <table width="100%" border="0" cellspacing="0"
cellpadding="2">
              <tr>
               <td>
                <select name="selectFont" onChange="FormatText('fontname',
selectFont.options[selectFont.selectedIndex].value);document.frmAddMessage.selectFont.options[0].selected
= true;"  >
                 <option selected>-- Font --</option>
                 <option value="Arial, Helvetica,
sans-serif">Arial</option>
                 <option value="Courier New, Courier, mono">Courier
New</option>
                 <option value="Times New Roman, Times, serif">Times New
Roman</option>
                 <option value="Verdana, Arial, Helvetica,
sans-serif">Verdana</option>
                </select>
                <select name="selectSize" onChange="FormatText('fontsize',
selectSize.options[selectSize.selectedIndex].value);document.frmAddMessage.selectSize.options[0].selected
= true;" >
                 <option selected>-- Dimensioni --</option>
                 <option value="1">1</option>
                 <option value="2">2</option>
                 <option value="3">3</option>
                 <option value="4">4</option>
                 <option value="5">5</option>
                 <option value="6">6</option>
                </select>
                <select name="selectColour"
onChange="FormatText('ForeColor',
selectColour.options[selectColour.selectedIndex].value);document.frmAddMessage.selectColour.options[0].selected
= true;" >
                 <option value="0" selected>-- Colore --</option>
                 <option value="black">Nero</option>
                 <option value="white">Bianco</option>
                 <option value="blue">Blu</option>
                 <option value="red">Rosso</option>
                 <option value="green">Verde</option>
                 <option value="yellow">Giallo</option>
                 <option value="orange">Arancione</option>
                 <option value="brown">Marrone</option>
                 <option value="magenta">Magenta</option>
                 <option value="cyan">Ciano</option>
                 <option value="limegreen">Verde Chiaro</option>
                </select>
               </td>
              </tr>
              <tr>
               <td> 
			   <a href="javascript:FormatText('cut');">Taglia</a>
               <a href="javascript:Formattext('copy');">copia</a>
			   <a href="javascript:Formattext('paste');">Incolla</a>
               <a href="javascript:FormatText('bold', '');"><img
src="../img/g_off.gif" width="23" height="22" align="absmiddle"
alt="Grassetto" onClick="status_bott(this);" border="0"></a><a
href="javascript:FormatText('italic', '')"><img src="../img/c_off.gif"
width="23" height="22" align="absmiddle" alt="Corsivo"
onClick="status_bott(this);" style="cursor: hand;" border="0"
hspace="1"></a><a href="javascript:FormatText('underline', '');"><img
src="../img/s_off.gif" width="23" height="22" align="absmiddle"
alt="Sottolineato" onClick="status_bott(this);" border="0"></a>
<a href="javascript:FormatText('JustifyLeft', '');">Left</a>
<a href="javascript:FormatText('JustifyCenter', '');">Center</a>         
<a href="javascript:FormatText('JustifyRight', '');">Right</a>
<a href="javascript:FormatText('InsertUnorderedList', '');">Unord.
List</a>                    
<a href="javascript:FormatText('Outdent', '');">Rid. rientro</a>           
<a href="javascript:FormatText('indent', '');">Aum. rientro</a>        
<a href="javascript:FormatText('createLink');">Link</a>
<a href="javascript:FormatText('Unlink');">Annulla Link</a>
<a href="javascript:FormatText('ForeColor','red');">Testo rosso</a>      
<a href="javascript:FormatText('BackColor','yellow');">Evidenzia</a>
<a href="javascript:FormatText('RemoveFormat');">Annulla format.</a>     
<a href="javascript:FormatText('SelectAll');">Seleziona tutto</a>
<a href="javascript:FormatText('SaveAs');">Salva</a>
<a href="javascript:FormatText('Print');">Stampa</a>
<a href="javascript:ester();">Preferiti</a>            <!--     <a
href="javascript:openWin('IE_emoticons_smilies.asp','smilies','toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=1,width=400,height=400')"><img
src="forum_images/post_button_smiley.gif" width="25" height="24"
align="absmiddle" alt="Emoticon Smilies" border="0"></a> --></td>         
 
		</tr>
             </table>
            </td>
 
           </tr>
          </table>
         </td>
        </tr>
        <tr > 
         <td valign="top" align="right" height="61" width="15%" ><span
class="text">Messaggio*:</span></td>
         <td height="61" width="85%" valign="top">
 
          <script language="javascript">
 
		    	//Create an iframe and turn on the design mode for it
		    	document.write ('<iframe src="scrivi.htm" id="message" width="510"
height="200"></iframe>')
                    	frames.message.document.designMode = "On";
 
                    </script>
          <!-- Display a message for IE users with JavaScript turned off
-->
          <noscript><span class="bold"><br><br>JavaScript deve essre
abilitato sul tuo browser per inviare messaggi al forum!</span></noscript>
</td>
        </tr>
 
        <tr> 
         <td align="right" height="7" width="92">&nbsp;</td>
         <td height="7" width="508" valign="bottom" class="white">
 
          &nbsp;<input type="checkbox" name="signature" value="True"
checked><span class="text">Mostra Firma</span>&nbsp;
 
         </td>
        </tr>
 
        <td> 
         <input type="hidden" name="message" value="">
         <input type="hidden" name="mode" value="reply">
         <input type="hidden" name="ForumID" value="2">
         <input type="hidden" name="TopicID" value="71">
         <input type="hidden" name="MessageID" value="365">
         <input type="hidden" name="ThreadPage" value="1">
         <input type="hidden" name="ThreadPos" value="4">
         <input type="hidden" name="browser" value="IE">
         &nbsp;</td>
        <td height="2" width="85%" align="left"> 
         <p> 
 
          <input type="button" name="Submit" value="Invia Risposta"
OnClick="document.frmAddMessage.prova.value =
frames.message.document.body.innerHTML;" tabindex="30">
 
          <input type="reset" name="Reset" value="Pulisci il Form">
         </p>
        </td>
        </tr>
       </table>
      </td>
     </tr>
    </table>
   </td>
  </tr>
  <tr>
  	<td><textarea cols="50" rows="10" name="prova"></textarea></td>
  </tr>
 </table>
</form> 
  <br>
</div>
</body>
</html>
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it