erro estranho javascript

alfinete

Power Member
code aspx


Código:
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="teste3.aspx.cs" Inherits="Framework.teste3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>   
    <script language="javascript" type="text/javascript">

    function Iniciar() 
    {
     document.getElementById("editor").contentWindow.document.designMode = "on";
     try
     {
       document.getElementById("editor").contentWindow.document.execCommand("undo", false, null);
     }  
     catch (e)
      {
      
      }
    }

    function recortar()
     {
        document.getElementById("editor").contentWindow.document.execCommand('cut', false, null);
        try
        {
         document.getElementById("editor").contentWindow.contentDocument.execCommand("cut", false, null);
        }
        catch(e){}
       
        
    }

    function copiar()
     {
        document.getElementById("editor").contentWindow.document.execCommand('copy', false, null);
        try
         {
        document.getElementById("editor").contentWindow.contentDocument.execCommand("copy", false, null);
        }
        catch (e){}
       
    }
    
    function colar()
     {
      document.getElementById("editor").contentWindow.document.execCommand('paste', false, null);
        try
         {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("paste", false, null);
        }  catch 
        (e){}
       
        
    }

    function desfazer() {
    
      document.getElementById("editor").contentWindow.document.execCommand('undo', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("undo", false, null);
        }  catch 
        (e){}
        
    }

    function refazer() {
      document.getElementById("editor").contentWindow.document.execCommand('redo', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("redo", false, null);
        }  catch 
        (e){}
        
    }

    function negrito() {
    
      document.getElementById("editor").contentWindow.document.execCommand('bold', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("bold", false, null);
        }  catch 
        (e){}
        
    }

    function italico() {
        document.getElementById("editor").contentWindow.document.execCommand('italic', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("italic", false, null);
     }  catch (e) {
       
     }
    }

    function sublinhado() {
        document.getElementById("editor").contentWindow.document.execCommand('underline', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("underline", false, null);
     }  catch (e) {
       
     }
        
    }

    function alinharEsquerda()
     {
        document.getElementById("editor").contentWindow.document.execCommand('justifyleft', false, null);
        try
        {
        document.getElementById("editor").contentWindow.contentDocument.execCommand("justifyleft", false, null);
        }
        catch (e) {}
        
    }

    function centralizado()
    {
    
        document.getElementById("editor").contentWindow.document.execCommand('justifycenter', false, null);
        try
         {
        document.getElementById("editor").contentWindow.contentDocument.execCommand("justifycenter", false, null);
        }
        catch (e) {}
        
    }

    function alinharDireita() 
    {
    
        document.getElementById("editor").contentWindow.document.execCommand('justifyright', false, null);
        try
         {
            document.getElementById("editor").contentWindow.contentDocument.execCommand("justifyright", false, null);
         }
         catch (e) {
       
     }
    
    
    }

    function numeracao() 
    {
    
        document.getElementById("editor").contentWindow.document.execCommand('insertorderedlist', false, null);
        try
        {
        document.getElementById("editor").contentWindow.contentDocument.execCommand("insertorderedlist", false, null);
        }
      catch (e) {}
    }

    function marcadores()
     {
    
        document.getElementById("editor").contentWindow.document.execCommand('insertunorderedlist', false, null);
        try
         {
            document.getElementById("editor").contentWindow.contentDocument.execCommand("insertunorderedlist", false, null);
         }
          catch (e) {}
                  
    }

    function fonte(fonte)
     {
    
        if(fonte != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand('fontname', false, fonte);
                try {
                   document.getElementById("editor").contentWindow.contentDocument.execCommand("fontname", false, fonte);
                    }
                   catch (e) {}
        }
        
    }

    function tamanho(tamanho)
     {
        
        if(tamanho != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand("fontsize", false, tamanho);
            try
                {
                
                document.getElementById("editor").contentWindow.contentDocument.execCommand("fontsize", false, tamanho);
                       
                }  
                 catch (e)
                 {
                   
                 }
        }
        
    
    </script>

</head>
<body onload="Iniciar()" bgcolor="#EFEDE1">
    <table align="center" width="600px" height="30px" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="center">
                <select name="fonte" onchange="javascript:fonte(this.options[this.selectedIndex].value)">
                    <option value=""></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="Times New Roman">Times New Roman</option>
                    <option value="Verdana">Verdana</option>
                </select>
                &nbsp;
                <select name="tamanho" onchange="javascript:tamanho(this.options[this.selectedIndex].value)">
                    <option value=""></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>
            </td>
            <td align="center">
                <!-- Recortar -->
                <img alt="Cortar" src="../Imagens/recortar.gif" onclick="javascript:recortar()" style="cursor: hand" />
                <!-- Copiar -->
                <img alt="Copiar" src="../Imagens/copiar.gif" onclick="javascript:copiar()" style="cursor: hand" />
                <!-- Colar -->
                <img alt="Colar" src="../Imagens/colar.gif" onclick="javascript:colar()" style="cursor: hand" />
                <!-- Desfazer -->
                <img alt="Voltar Atrás" src="../Imagens/desfazer.gif" onclick="javascript:desfazer()" style="cursor: hand" />
                <!-- Refazer -->
                <img alt="Voltar frente" src="../Imagens/refazer.gif" onclick="javascript:refazer()" style="cursor: hand" />
                <!-- Negrito -->
                <img alt="negrito" src="../Imagens/negrito.gif" onclick="javascript:negrito()" style="cursor: hand" />
                <!-- Itálico -->
                <img alt="tálico" src="../Imagens/italico.gif" onclick="javascript:italico()" style="cursor: hand" />
                <!-- Sublinhado -->
                <img alt="Sublinhado" src="../Imagens/sublinhado.gif" onclick="javascript:sublinhado()" style="cursor: hand" />
                <!-- Alinhar à Esquerda -->
                <img alt="Alinhar esquerda" src="../Imagens/alinhamentoesquerda.gif" onclick="javascript:alinharEsquerda();"
                    style="cursor: hand" />
                <!-- Alinhar ao Centro -->
                <img alt="Centrar" src="../Imagens/centralizado.gif" onclick="javascript:centralizado()" style="cursor: hand" />
                <!-- Alinha à Direita -->
                <img alt="Alinhar Direita" src="../Imagens/alinhamentodireita.gif" onclick="javascript:alinharDireita()" style="cursor: hand" />
                <!-- Numeração -->
                <img alt="Numeração" src="../Imagens/numeracao.gif" onclick="javascript:numeracao()" style="cursor: hand" />
                <!-- Marcadores -->
                <img alt="Marcadores" src="../Imagens/marcador.gif" onclick="javascript:marcadores()" style="cursor: hand" />
            </td>
        </tr>
    </table>
    <center>
        <iframe id="editor" frameborder="2" style="border: 1px solid; width: 582px; height: 350px"
            runat="server"></iframe>
        <br />
        <br />
        <font size="-1">Editor de Texto JavaScript
            <br>
        </font>
    </center>
</body>
</html>



code html

_______________________________


Código:
<html>
<head>
<title>Editor de Texto JavaScript ::: Linha de Código</title>
<script language="JavaScript">

    function Iniciar() 
    {
     document.getElementById("editor").contentWindow.document.designMode = "on";
     try {
       document.getElementById("editor").contentWindow.document.execCommand("undo", false, null);
     }  catch (e) {
      
     }
    }
    /*function Iniciar() {
        editor.document.designMode = "On" ;
    }*/

    function recortar() {
        document.getElementById("editor").contentWindow.document.execCommand('cut', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("cut", false, null);
        }  catch 
        (e){}
       
        
    }

    function copiar() {
        document.getElementById("editor").contentWindow.document.execCommand('copy', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("copy", false, null);
        }  catch 
        (e){}
       
    }
    
    function colar() {
      document.getElementById("editor").contentWindow.document.execCommand('paste', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("paste", false, null);
        }  catch 
        (e){}
       
        
    }

    function desfazer() {
    
      document.getElementById("editor").contentWindow.document.execCommand('undo', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("undo", false, null);
        }  catch 
        (e){}
        
    }

    function refazer() {
      document.getElementById("editor").contentWindow.document.execCommand('redo', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("redo", false, null);
        }  catch 
        (e){}
        
    }

    function negrito() {
    
      document.getElementById("editor").contentWindow.document.execCommand('bold', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("bold", false, null);
        }  catch 
        (e){}
        
    }

    function italico() {
        document.getElementById("editor").contentWindow.document.execCommand('italic', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("italic", false, null);
     }  catch (e) {
       
     }
    }

    function sublinhado() {
        document.getElementById("editor").contentWindow.document.execCommand('underline', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("underline", false, null);
     }  catch (e) {
       
     }
        
    }

    function alinharEsquerda() {
        document.getElementById("editor").contentWindow.document.execCommand('justifyleft', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("justifyleft", false, null);
     }  catch (e) {
       
     }
        
    }

    function centralizado()    {
    
            document.getElementById("editor").contentWindow.document.execCommand('justifycenter', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("justifycenter", false, null);
     }  catch (e) {
       
     }
        
    }

    function alinharDireita() {
    
            document.getElementById("editor").contentWindow.document.execCommand('justifyright', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("justifyright", false, null);
     }  catch (e) {
       
     }
    
    
    }

    function numeracao() {
    
        document.getElementById("editor").contentWindow.document.execCommand('insertorderedlist', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("insertorderedlist", false, null);
     }  catch (e) {
       
     }
    
    }

    function marcadores() {
    
    document.getElementById("editor").contentWindow.document.execCommand('insertunorderedlist', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("insertunorderedlist", false, null);
     }  catch (e) {
       
     }
    
        
    }

    function fonte(fonte) {
    
        if(fonte != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand('fontname', false, fonte);
                try {
               document.getElementById("editor").contentWindow.contentDocument.execCommand("fontname", false, fonte);
             }  catch (e) {
               
             }
        }
        
    }

    function tamanho(tamanho) {
        
        if(tamanho != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand("fontsize", false, tamanho);
            try
                {
                
                document.getElementById("editor").contentWindow.contentDocument.execCommand("fontsize", false, tamanho);
                       
                }  
                 catch (e) {
                   
                 }
        }
        
    
           
        
         
        
    }
    


</script>

<body onLoad="Iniciar()" bgcolor="#EFEDE1">
<table align="center" width="600px" height="30px" border="0" cellspacing="0" cellpadding="0" >    
    <tr>
    <td align="center">

    <select name="fonte" onChange="fonte(this.options[this.selectedIndex].value)">
        <option value=""></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="Times New Roman">Times New Roman</option>
        <option value="Verdana">Verdana</option>
    </select>
    &nbsp;        
    <select name="tamanho" onChange="tamanho(this.options[this.selectedIndex].value)">
        <option value=""></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>

    </td>

    <td align="center">
        
        <!-- Recortar -->
        <img alt="Cortar" src="recortar.gif" onClick="recortar()" style="cursor:hand">
            
        <!-- Copiar -->
        <img alt="Copiar" src="copiar.gif" onClick="copiar()" style="cursor:hand">
            
        <!-- Colar -->
        <img src="colar.gif" onClick="colar()" style="cursor:hand">
            
        <!-- Desfazer --> 
        <img src="desfazer.gif" onClick="desfazer()" style="cursor:hand">
            
        <!-- Refazer -->
        <img src="refazer.gif" onClick="refazer()" style="cursor:hand">
            
        <!-- Negrito --> 
        <img src="negrito.gif" onClick="negrito()" style="cursor:hand">
            
        <!-- Itálico -->
        <img src="italico.gif" onClick="italico()" style="cursor:hand">
            
        <!-- Sublinhado -->
        <img src="sublinhado.gif" onClick="sublinhado()" style="cursor:hand">
            
        <!-- Alinhar à Esquerda -->
        <img src="alinhamentoesquerda.gif" onClick="alinharEsquerda();" style="cursor:hand">
            
        <!-- Alinhar ao Centro -->
        <img src="centralizado.gif" onClick="centralizado()" style="cursor:hand">
            
        <!-- Alinha à Direita -->
        <img src="alinhamentodireita.gif" onClick="alinharDireita()" style="cursor:hand">
            
        <!-- Numeração -->
        <img src="numeracao.gif" onClick="numeracao()" style="cursor:hand">

        <!-- Marcadores -->
        <img src="marcador.gif" onClick="marcadores()" style="cursor:hand">
    
    </td>
    </tr>
    </table>

    <center>
    
            <iframe id="editor" frameborder="2" 
        style="border:1px solid; width: 582px; height:350px"></iframe>

        
    <br><br>
    
    <font size="-1">
        Editor de Texto JavaScript <br>
        
    </font>
    </center>

</body>
</html>


no code html corre perfeitamente sem erros de javacript



no aspx da erro expected } na linha 192


não sei pq


agradecia uma ajuda
 
no code html corre perfeitamente sem erros de javacript



no aspx da erro expected } na linha 192


não sei pq


agradecia uma ajuda

Vo te contar um segredo:
quando da esse erro é porque esta a faltar }algum lado provavelmente.

observa este pedaço do teu código aspx:
Código:
   function tamanho(tamanho)
     {
        
        if(tamanho != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand("fontsize", false, tamanho);
            try
                {
                
                document.getElementById("editor").contentWindow.contentDocument.execCommand("fontsize", false, tamanho);
                       
                }  
                 catch (e)
                 {
                   
                 }
        }
        
    
    </script>

contei mais { do que }, quando comparei isto com o teu codigo em html descobri que fizeste copy paste mal, no html tens um } que aqui não tens
 
thenka pela ajuda esse problem resolvido


Código:
<%@ Control Language="C#" AutoEventWireup="true" Codebehind="wucEditortexto.ascx.cs"
    Inherits="Framework.WuControl.Editortexto" %>
    
<script language="JavaScript" type="text/javascript"  >

    function Iniciar() 
    {
     document.getElementById("editor").contentWindow.document.designMode = "on";
     try {
       document.getElementById("editor").contentWindow.document.execCommand("undo", false, null);
     }  catch (e) {
      
     }
    }
    /*function Iniciar() {
        editor.document.designMode = "On" ;
    }*/

    function recortar() {
        document.getElementById("editor").contentWindow.document.execCommand('cut', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("cut", false, null);
        }  catch 
        (e){}
       
        
    }

    function copiar() {
        document.getElementById("editor").contentWindow.document.execCommand('copy', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("copy", false, null);
        }  catch 
        (e){}
       
    }
    
    function colar() {
      document.getElementById("editor").contentWindow.document.execCommand('paste', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("paste", false, null);
        }  catch 
        (e){}
       
        
    }

    function desfazer() {
    
      document.getElementById("editor").contentWindow.document.execCommand('undo', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("undo", false, null);
        }  catch 
        (e){}
        
    }

    function refazer() {
      document.getElementById("editor").contentWindow.document.execCommand('redo', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("redo", false, null);
        }  catch 
        (e){}
        
    }

    function negrito() {
    
      document.getElementById("editor").contentWindow.document.execCommand('bold', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("bold", false, null);
        }  catch 
        (e){}
        
    }

    function italico() {
        document.getElementById("editor").contentWindow.document.execCommand('italic', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("italic", false, null);
     }  catch (e) {
       
     }
    }

    function sublinhado() {
        document.getElementById("editor").contentWindow.document.execCommand('underline', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("underline", false, null);
     }  catch (e) {
       
     }
        
    }

    function alinharEsquerda() {
        document.getElementById("editor").contentWindow.document.execCommand('justifyleft', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("justifyleft", false, null);
     }  catch (e) {
       
     }
        
    }

    function centralizado()    {
    
            document.getElementById("editor").contentWindow.document.execCommand('justifycenter', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("justifycenter", false, null);
     }  catch (e) {
       
     }
        
    }

    function alinharDireita() {
    
            document.getElementById("editor").contentWindow.document.execCommand('justifyright', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("justifyright", false, null);
     }  catch (e) {
       
     }
    
    
    }

    function numeracao() {
    
        document.getElementById("editor").contentWindow.document.execCommand('insertorderedlist', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("insertorderedlist", false, null);
     }  catch (e) {
       
     }
    
    }

    function marcadores() {
    
    document.getElementById("editor").contentWindow.document.execCommand('insertunorderedlist', false, null);
        try {
       document.getElementById("editor").contentWindow.contentDocument.execCommand("insertunorderedlist", false, null);
     }  catch (e) {
       
     }
    
        
    }

    function fonte(fonte) {
    
        if(fonte != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand('fontname', false, fonte);
                try {
               document.getElementById("editor").contentWindow.contentDocument.execCommand("fontname", false, fonte);
             }  catch (e) {
               
             }
        }
        
    }

    function tamanho(tamanho) {
        
        if(tamanho != '')
        {
            document.getElementById("editor").contentWindow.document.execCommand("fontsize", false, tamanho);
            try
                {
                
                document.getElementById("editor").contentWindow.contentDocument.execCommand("fontsize", false, tamanho);
                       
                }  
                 catch (e) {
                   
                 }
        }
        
    
           
        
         
        
    }
    </script>


<div onload="javascript:Iniciar();" bgcolor="#EFEDE1" >
    <table align="center" width="600px" height="30px" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="center">
                <select name="fonte" onchange="javascript:fonte(this.options[this.selectedIndex].value)">
                    <option value=""></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="Times New Roman">Times New Roman</option>
                    <option value="Verdana">Verdana</option>
                </select>
                &nbsp;
                <select name="tamanho" onchange="javascript:tamanho(this.options[this.selectedIndex].value)">
                    <option value=""></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>
            </td>
            <td align="center">
                <!-- Recortar -->
                <img alt="Cortar" src="../Imagens/recortar.gif" onclick="javascript:recortar()" style="cursor: hand" />
                <!-- Copiar -->
                <img alt="Copiar" src="../Imagens/copiar.gif" onclick="javascript:copiar()" style="cursor: hand" />
                <!-- Colar -->
                <img alt="Colar"  src="../Imagens/colar.gif" onclick="javascript:colar()" style="cursor: hand" />
                <!-- Desfazer -->
                <img alt="Desfazer"  src="../Imagens/desfazer.gif" onclick="javascript:desfazer()" style="cursor: hand" />
                <!-- Refazer -->
                <img alt="Refazer" src="../Imagens/refazer.gif" onclick="javascript:refazer()" style="cursor: hand" />
                <!-- Negrito -->
                <img alt="Negrito" src="../Imagens/negrito.gif" onclick="javascript:negrito()" style="cursor: hand" />
                <!-- Itálico -->
                <img alt="Itálico" src="../Imagens/italico.gif" onclick="javascript:italico()" style="cursor: hand" />
                <!-- Sublinhado -->
                <img alt="Sublinhado" src="../Imagens/sublinhado.gif" onclick="javascript:sublinhado()" style="cursor: hand" />
                <!-- Alinhar à Esquerda -->
                <img alt="Alinhar Esquerda" src="../Imagens/alinhamentoesquerda.gif" onclick="javascript:alinharEsquerda();"
                    style="cursor: hand" />
                <!-- Alinhar ao Centro -->
                <img alt="Centrar" src="../Imagens/centralizado.gif" onclick="javascript:centralizado()" style="cursor: hand" />
                <!-- Alinha à Direita -->
                <img alt="Alinhar direita" src="../Imagens/alinhamentodireita.gif" onclick="javascript:alinharDireita()"
                    style="cursor: hand" />
                <!-- Numeração -->
                <img alt="numeração" src="../Imagens/numeracao.gif" onclick="javascript:numeracao()" style="cursor: hand" />
                <!-- Marcadores -->
                <img alt="Marcadores" src="../Imagens/marcador.gif" onclick="javascript:marcadores()" style="cursor: hand" />
            </td>
        </tr>
    </table>
    <center>
        <iframe id="editor" frameborder="2" style="border: 1px solid; width: 582px; height: 350px"
            runat="server"></iframe>
        <br />
        <br />
        <font size="-1">Editor de Texto JavaScript
            <br>
        </font>
    </center>
</div>

agora pus isso tdo num user control, mas ele não me deixa escrever nada depois como não ha nada escrito e clico numa das opções do editor ele rebenta


agradecia um help
 
Back
Topo