Ver Mensaje Individual
  #3 (permalink)  
Antiguo 04/11/2012, 08:39
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Se puede pasar variables/return de funciones entre archivos src de un html

Bueno, tecnicamente es posible, aunque pudiendo hacer lo que señala @caricatos, no le encuentro mucha utilidad

get_js.js
Código Javascript:
Ver original
  1. window.onload = function() {
  2. var nombre;
  3. var url_script = document.getElementById("script_uno").getAttribute("src");
  4. var qs = url_script.substring(url_script.indexOf("?") + 1, url_script.length);
  5. var parametros = qs.split("&");
  6. for(var i = 0; i < parametros.length; i++){
  7.  var name  = parametros[i].substring(0,parametros[i].indexOf("="));
  8.  var value = parametros[i].substring(parametros[i].indexOf("=") + 1, parametros[i].length);
  9. // por si querés pasar números
  10.     if(isNaN(parseInt(value))) {
  11.   parametros[i] = parametros[i].replace(value, "'" + value + "'");
  12.  }
  13.  eval(parametros[i]);
  14. }
  15. document.getElementById("nombre").innerHTML = nombre;
  16. };

get_js.html

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>Get En js</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script id="script_uno" type="text/javascript" src="get_js.js?nombre=Emprear"></script>
  7. </head>
  8. <h1 id="nombre"><!-- fix --></h1>
  9. </body>
  10. </html>

Probada en IE9/FF/Chrome

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.