Foros del Web » Programando para Internet » Javascript »

Error con codigo javascript: warning: curly braces

Estas en el tema de Error con codigo javascript: warning: curly braces en el foro de Javascript en Foros del Web. Hola a todos como estan... Resulta que me pasaron un codigo que tengo que insertar en una pagina de un cliente y el mismo no ...
  #1 (permalink)  
Antiguo 30/06/2012, 15:43
 
Fecha de Ingreso: junio-2001
Ubicación: Rosario
Mensajes: 1.434
Antigüedad: 22 años, 10 meses
Puntos: 2
Sonrisa Error con codigo javascript: warning: curly braces

Hola a todos como estan...

Resulta que me pasaron un codigo que tengo que insertar en una pagina de un cliente y el mismo no funciona da error, creo que el error es de corcheas en los if y la aplicacion vbulletin no me deja ponerlo por esa razon...

Pueden probar el codigo en esta pagina para ver el error:

http://www.javascriptlint.com/online_lint.php

Y el Codigo que deben insertar para ver el error es este:

Código:
<script>
if (typeof(__cpa_setup) == 'undefined') var __cpa_setup = {398:{}};
if (typeof(__cpa_setup[398]) == 'undefined') __cpa_setup[398] = {};
__cpa_setup[398][0] = {
param: {
's': '',
'r': 'pagina.com',
'f': '',
'cs': typeof(document.characterSet) == 'undefined' ? document.defaultCharset : document.characterSet,
'u': ''
},
text: {
mediagetCaption10: "Descargar Gratis: ",
mediagetCaption11: "Gratis",
mediagetDownload1: "Descargar Gratis",
mediagetDesc1: "Descarga Gratis con MediaGet",
mediaCaption1: "Descargar Gratis: ",
mediaCaption2: "Gratis",
mediaDownload1: "Descargar Gratis",
mediaDesc1: "Descarga Gratis con MediaGet"
}
};
__cpa_setup[398][0]['param']['s'] = document.title;
__cpa_setup[398][0]['param']['f'] = __cpa_setup[398][0]['param']['s'];
</script>
<div align="center">
<div id="cpa_rotator_block_398_0">
<div style="width:468px;height:60px;overflow:hidden; background:#f2f4bd; border-left:1px solid #d4d4d4;overflow:hidden;">
<h2 style="text-align:center;margin:10px 1px 0 10px;padding:0;color:#000;font-family: arial;font-size: 16px;cursor:default; overflow:hidden;"><span id="mediagetCaption10398_0"></span><span id="mediagetFile1398_0">__rotator_param_f</span><span id="mediagetCaption11398_0"></span></h2>
<a id="mediagetLink1398_0" href="" style="text-decoration: underline; display:block; margin:6px 10px 0 0; font-size: 16px; background:#f2f4bd;width:121px;height:30px;text-align: center;color:#000;font-weight: bold;font-family: arial; cursor:pointer"><font id="mediagetDownload1398_0"></font></a>
<p id="mediagetDesc1398_0" style="text-align:center;margin:5px 2px 0 2px; padding:0;color:#000;font-family: arial;font-size: 11px;cursor:default;"></p>
<div style="clear:both;"></div>
</div>
<script type="text/javascript">
key = '398_0';
try {
setup = __cpa_setup[398][0];
for ( name in setup['text'] ) {
document.getElementById(name + key).innerHTML = setup['text'][name];
}
s = setup['param'].s;
f = setup['param'].f;
cs = setup['param'].cs;
r = setup['param'].r;
document.getElementById('mediagetFile1' + key).innerHTML = f;
document.getElementById('mediagetLink1' + key).href = "http://mediaget.com/torrent.php?r="+r+"&s="+s+"&f="+f+"&cs="+cs;
} catch (e) {}
try {
text_button = document.getElementById('mediagetFile1' + key).innerHTML.replace(/\s+/g, ' ');
text_caption1 = document.getElementById('mediagetCaption10' + key).innerHTML;
text_caption2 = document.getElementById('mediagetCaption11' + key).innerHTML;
caption_max = 51;
caption_length = text_button.length + text_caption1.length + text_caption2.length;
optimal_length = caption_max - text_caption1.length - text_caption2.length;
if (optimal_length < 10) optimal_length = 10;
if ( caption_length > caption_max ){
document.getElementById('mediagetFile1' + key).innerHTML = text_button.substring(0, optimal_length - 3).replace(/\s*$/, '') + "...";
}
} catch (e) {}
</script>
</div>
<script type="text/javascript" src="http://bubblesmedia.ru/invoke.php?id=398&subid=0"></script>
</div>
El error que veo es el siguiente:

1 <script>
2 if (typeof(__cpa_setup) == 'undefined') var __cpa_setup = {398:{}};
========================================^
lint warning: block statement without curly braces
3 if (typeof(__cpa_setup[398]) == 'undefined') __cpa_setup[398] = {};
=============================================^
lint warning: block statement without curly braces


55 if (optimal_length < 10) optimal_length = 10;
=========================^
lint warning: block statement without curly braces

Pueden darme una ayuda con esas lineas ?

Gracias desde ya :)
  #2 (permalink)  
Antiguo 01/07/2012, 08:38
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Error con codigo javascript: warning: curly braces

Lo que a todas luces te está indicando es:
En lugar de hacer esto:
Código PHP:
if(5==30)alert('son iguales'); 
Haz esto otro:
Código PHP:
if(5==30){alert('son iguales');} 
Es decir: agrega la llaves. No es que no funcione. Es una recomendación de la herramienta que estás usando.

Etiquetas: funcion, html, php, warning
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:29.