To pass information from one page (form.aspx) to another window that opens from the first one (edit.aspx), you have several options:
1) Pass the information in the GET
Similar to how the name of the field is passed, you can pass the value (if it is not too large) as part of the URL:
function ZoomEdit2(campo) {
// obtener el valor del campo (podría hacerse de diferentes maneras)
var valor = document.getElementById(campo).value;
// abrir la ventana pasando los valores en la URL
var nw = window.open("../Plugins/editar.aspx?campo=" + campo + "&valor=" + valor,"FORMATO","resizable=1,width=1100,height=600, scrollbars=1");
nw.focus();
}
Advantages of this method:
- Simple
- Implementation similar to the
campo
attribute that you already process
Disadvantages of this method:
- There is a limit on the size of the value you can spend
- Users can see the value (it does not offer much privacy or security)
2) Save the values in the LocalStorage
Another option would be to save the value in LocalStorage
or SessionStorage
before opening the window and then read the value in the new window when it loads.
function ZoomEdit2(campo) {
// guardar el valor del campo en el localStorage (podría hacerse de diferentes maneras)
localStorage.setItem('myCat', document.getElementById(campo).value );
var nw = window.open("../Plugins/editar.aspx?campo=" + campo + "","FORMATO","resizable=1,width=1100,height=600, scrollbars=1");
nw.focus();
}
Advantages of this method:
- Simple and easy to implement
- You can save more data than you could pass through the URL
Disadvantages of this method:
- It will not work if the user has cookies disabled
- It will not work if the protocols do not match (http or https, but not both)
3) Read the father's data from the open window
As indicated in the comments and in another answer, you could access the values of the father using window.parent
, so from the open window you can read the field you want like this:
var valorEnPadre = window.opener.document.getElementById("ID_DEL_ELEMENTO").value;
Assuming that the item ID was saved in the campo
attribute, then it would be:
var valorEnPadre = window.opener.document.getElementById(campo).value;
Advantages of this method:
- Pure and hard JavaScript with no APIs that can fail or browser compatibility issues
- There should be no size problems
Disadvantages of this method:
- Requires that the pages be on a server (works with http or https but not with file: //)