Ver Mensaje Individual
  #20 (permalink)  
Antiguo 14/07/2015, 17:15
Papito18
 
Fecha de Ingreso: julio-2012
Ubicación: Nómoda como un ave
Mensajes: 61
Antigüedad: 12 años, 7 meses
Puntos: 0
Respuesta: abrir ventana y mandar parámetros

Cita:
Iniciado por NSD Ver Mensaje
padre.html
Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.     <head>
  3.         <meta charset="utf-8">
  4.         <title>Box Ventanas</title>
  5.         <style>
  6.             .modal {
  7.                 position: fixed;
  8.                 z-index: 9999;
  9.                 top: 0;
  10.                 left: 0;
  11.                 right: 0;
  12.                 bottom: 0;
  13.                 background: rgba(0,0,0,.8);
  14.             }
  15.             .modal > div {
  16.                 width: 80%;
  17.                 height: 100vh;
  18.                 padding: 20px;
  19.                 margin: 0 auto;
  20.                 background-color: #FFF;
  21.                 box-shadow: 0 0 10px #000000;
  22.             }
  23.             .modal > div > h2 {
  24.                 margin:0;
  25.                 padding:0 0 10px 0px;
  26.                 border-bottom:1px #ccc solid;
  27.                 font-size:22px;
  28.             }
  29.             .modal > div > div{
  30.                 display:block;
  31.                 padding:10px 0 0 0px;
  32.                 font-size:18px;
  33.                 line-height:22px;
  34.             }
  35.             .modal > div > span {
  36.                 float:right;
  37.                 display:block;
  38.                 font-size:22px;
  39.                 color:#858585;
  40.             }
  41.         </style>
  42.         <script>
  43.             Modal = function(url) {
  44.                 this.open = this.open.bind(this);
  45.                 this.close = this.close.bind(this);
  46.                 this.load = this.load.bind(this);
  47.  
  48.                 this.url = url;
  49.                 this.box = null;
  50.             }
  51.  
  52.             Modal.prototype = {
  53.                 "open" : function(title, params) {
  54.                     this.load(params, function(status, responseText) {
  55.                         var templ = document.createElement("template");
  56.                         templ.innerHTML = '<div>'+
  57.                                             '<span>X</span>'+
  58.                                             '<h2>' + title + '</h2>'+
  59.                                             '<div>' + responseText + '</div>'+
  60.                                           '</div>';
  61.                        
  62.                         this.box = document.createElement("div");                
  63.                         this.box.classList.add("modal");
  64.                         document.body.appendChild(this.box);
  65.                         this.box.appendChild(document.importNode(templ.content, true));
  66.                         this.box.firstChild.firstChild.addEventListener("click", this.close);
  67.                     });
  68.                 },
  69.                 "close" : function() {
  70.                     document.body.removeChild(this.box);
  71.                     this.box = null;
  72.                 },
  73.                 "load" : function(params, callback) {
  74.                     var request = new XMLHttpRequest();
  75.                     request.open("POST", this.url);
  76.                     request.onreadystatechange = function(callback) {
  77.                         if(this.readyState == 4)
  78.                             callback(this.status, this.responseText);
  79.                     }.bind(request, callback.bind(this));
  80.                     request.send(params);
  81.                 }
  82.             };
  83.         </script>
  84.     </head>
  85.     <body>
  86.         <h1>Modal de comunicacion entre paginas via AJAX</h1>
  87.         <form id="datos-origen">
  88.             <label>
  89.                 Un numero:
  90.                 <input type="text" name="numero" value="5">
  91.             </label>
  92.         </form>
  93.         <button id="open">ABRIR MODAL</button>
  94.  
  95.         <script>
  96.             document.getElementById("open").addEventListener("click", function(){
  97.                 var onemodal = new Modal("hijo.php");
  98.                 onemodal.open("Pagina hijo", new FormData(document.getElementById("datos-origen")));
  99.             });
  100.         </script>
  101.     </body>
  102. </html>

hijo.php
Código PHP:
Ver original
  1. Hola! Soy hijo.php, me mandaste el numero "<?=$_POST["numero"];?>", yo te devuelvo el doble, cuando cierres esta ventana lo vas a ver.
  2. <script>
  3.     document.getElementById("datos-origen").elements.numero.value = <?=($_POST["numero"]*2);?>;
  4. </script>

amigo, veo que tus scrips están en la misma pagina del contenido, yo estoy trabajando con funciones de js, en un documentos aparte donde creo tosas mis funciones y cada vez que ocupo una función las llamo de forma individual, me gustaría que me ayudaras a como resumo en una sola función tu escript, ´porque veo que tu tienes mas de una función y que se asocia con modal, y donde llamaría esta función.

ya separe el stilo a mi hoja de estilos pero el script aun no lo logro, espero me ayudes...