Foros del Web » Programando para Internet » Javascript » Frameworks JS »

error ejecutar js en ie

Estas en el tema de error ejecutar js en ie en el foro de Frameworks JS en Foros del Web. hola estoy intentando ejecutar codigo javascript. he usado codigo que encontre en este foro, pero me lanza 2 errores cuando uso IE. esto es lo ...
  #1 (permalink)  
Antiguo 24/02/2009, 08:48
Avatar de IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
error ejecutar js en ie

hola

estoy intentando ejecutar codigo javascript. he usado codigo que encontre en este foro, pero me lanza 2 errores cuando uso IE. esto es lo que tengo

en esta seccion me lanza error en la linea 1 y 37

prueba.js
Código javascript:
Ver original
  1. var tagScript = '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)';
  2. /**
  3. * Eval script fragment
  4. * @return String
  5. */
  6. String.prototype.evalScript = function()
  7. {
  8.         return (this.match(new RegExp(tagScript, 'img')) || []).evalScript();
  9. };
  10. /**
  11. * strip script fragment
  12. * @return String
  13. */
  14. String.prototype.stripScript = function()
  15. {
  16.         return this.replace(new RegExp(tagScript, 'img'), '');
  17. };
  18. /**
  19. * extract script fragment
  20. * @return String
  21. */
  22. String.prototype.extractScript = function()
  23. {
  24.         var matchAll = new RegExp(tagScript, 'img');
  25.         return (this.match(matchAll) || []);
  26. };
  27. /**
  28. * Eval scripts
  29. * @return String
  30. */
  31. Array.prototype.evalScript = function(extracted)
  32. {
  33.                 var s=this.map(function(sr){
  34.                 var sc=(sr.match(new RegExp(tagScript, 'im')) || ['', ''])[1];
  35.                 if(window.execScript){
  36.                 window.execScript(tagScript); // LINEA 37
  37.                 }
  38.                 else
  39.                 {
  40.                  window.setTimeout(sc,0);
  41.                 }
  42.                 });
  43.                 return true;
  44. };
  45. /**
  46. * Map array elements
  47. * @param {Function} fun
  48. * @return Function
  49. */
  50. Array.prototype.map = function(fun)
  51. {
  52.         if(typeof fun!=="function"){return false;}
  53.         var i = 0, l = this.length;
  54.         for(i=0;i<l;i++)
  55.         {
  56.                 fun(this[i]);
  57.         }
  58.         return true;
  59. };



prueba.html
Código html:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html xmlns="http://www.w3.org/1999/xhtml"lang="es" xml:lang="es">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <script type="text/javascript" src="prueba2.js"></script>
  5. <script type="text/javascript">
  6. function creaAjax(){
  7.     var ajaxs = ["Msxml2.XMLHTTP","Msxml2.XMLHTTP.4.0","Msxml2.XMLH TTP.5.0","Msxml2.XMLHTTP.3.0","Microsoft.XMLHTTP"];
  8.     var ajax = false;
  9.     for(var i=0 ; !ajax && i<ajaxs.length ; i++){
  10.         try{
  11.             ajax = new ActiveXObject(ajaxs[i]);   // Internet Explorer
  12.         }
  13.         catch(e) {
  14.             ajax = false;
  15.         }
  16.     }
  17.     if(!ajax && typeof XMLHttpRequest!='undefined') {
  18.         ajax = new XMLHttpRequest();  // Firefox, Opera 8.0+, Safari
  19.     }
  20.     return ajax;
  21. }
  22.  
  23.  
  24. function Evento() {
  25. var elemento = document.getElementById('hr');
  26. var nomevento = "click";
  27. var funcion = function() {
  28. Muestra("contenedor");
  29. }
  30.  
  31.     if (elemento.attachEvent)
  32.   {
  33.       var f=function(){
  34.         funcion.call(elemento,window.event);
  35.     }
  36.     elemento.attachEvent('on'+nomevento,f);
  37.     return true;
  38.   }
  39.   else  
  40.     if (elemento.addEventListener)
  41.     {
  42.       elemento.addEventListener(nomevento,funcion,false);
  43.       return true;
  44.     }
  45.     else
  46.       return false;
  47. }
  48.  
  49.  
  50. function Muestra(lugar) {
  51. var ajax=creaAjax();
  52. var objetosel = document.getElementById(lugar);
  53. ajax.open('GET','pruebaajax.asp',true);
  54. ajax.onreadystatechange = function() {
  55.  
  56.         if (ajax==null){
  57.         alert ("Tu navegador web no soporta AJAX!");
  58.         return;
  59.     }
  60.  
  61.         if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3) {
  62.                                         objetosel.innerHTML = "Cargando ...";
  63.             }
  64.  
  65.                 else if (ajax.readyState==4){
  66.                     if(ajax.status==200){          
  67.            
  68.         var scs=ajax.responseText.extractScript();
  69.             objetosel.innerHTML = ajax.responseText.stripScript();
  70.         scs.evalScript();
  71.  
  72.                    }
  73.                     else if (ajax.status==404)
  74.                                              {
  75.  
  76.                                     objetosel.innerHTML = "La dirección no existe";
  77.                                              }
  78.                                      else
  79.                                              {
  80.                                     objetosel.innerHTML = "Se ha producido un error.<br />Lo mas probable es que no hayas seleccionad una Fecha";
  81.                                              }
  82.                                     }
  83.                   }
  84.    
  85.     ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  86.             ajax.send(null);
  87.             return
  88. }
  89.  
  90. window.onload = Evento;
  91. </head>
  92.  
  93. <input type="button" name="hr" id="hr" value="Ver">
  94.  
  95. <br /><br /><br />
  96. <div id="contenedor"></div>
  97. </body>
  98. </html>

pruebaajax.asp
Código asp:
Ver original
  1. <%
  2. For i = 1 to 5
  3. Response.Write "<a href=""#"">" & i & "</a>"
  4. Next 'i
  5. %>
  6. <script type="text/javascript">
  7. var ref = document.getElementById("contenedor").getElementsByTagName("A");
  8. for (var i = 0; i < ref.length; i++) {
  9.   Valor(ref[i], 'click', function() {MuestraValor(this.id);})    
  10. }
  11. </script>

¿que estoy haciendo mal? el codigo lo he simplificado para una mejor compresion

gracias
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}
  #2 (permalink)  
Antiguo 04/02/2013, 14:06
 
Fecha de Ingreso: febrero-2013
Mensajes: 1
Antigüedad: 11 años, 2 meses
Puntos: 0
Respuesta: error ejecutar js en ie

Hola, tengo exactamente el mismo el problema actualmente, ¿Pudiste resolverlo?
Muchas gracias!!
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 07:01.