Ver Mensaje Individual
  #11 (permalink)  
Antiguo 28/04/2010, 17:37
Avatar de ilen
ilen
 
Fecha de Ingreso: febrero-2009
Mensajes: 125
Antigüedad: 15 años, 2 meses
Puntos: 2
Respuesta: Cargar script en div q viene d ajax

Cita:
Iniciado por Adler Ver Mensaje
Hola

Prueba así

leerjsdesdeajax.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(sc);
  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. };

el en html,php,asp...

Código Javascript:
Ver original
  1. <script type="text/javascript" src="./leerjsdesdeajax.js"></script>
  2.  
  3. .....
  4.  
  5. var scs=ajax.responseText.extractScript();
  6. obj.innerHTML = ajax.responseText.stripScript();
  7. scs.evalScript();

Suerte

Hay que usar librerias Prototype para que funciones esto?????