Requirements
Open another interface in one interface and obtain the value entered by the user in the other interface through JS.
Example:
Index.html
function EntryPoint() {
var style = 'dialogHeight:600px;dialogWidth:800px;status:no;help:0;scroll:yes';
var a = window.showModalDialog('other.html', '', style);
if (a == undefined) {
a = window.returnValue;
}
// debugger;
if (a != null && a.length > 0) {
document.getElementById("name").value = a[0];
document.getElementById("age").value = a[1];
}
}
Another interface:
other.html
function postValue() {
var name = document.getElementById("name").value;
var age = document.getElementById("age").value;
var a = new Array();
a[0] = name;
a[1] = age;
//debugger;
if (window.opener != undefined) {
//for chrome
window.opener.returnValue = a;
}
else {
window.returnValue = a;
}
window.close();
}
名字:
年龄:
在该DEMO中遇到一个问题,那就是chrome中window.close()方法不起作用。最后通过,window.opener来解决chrome和IE的冲突。