Javascript| Web page
Today, small asked me how a very common function in an AP can be written, that is, by pressing the Next button, a window opens, then return the value back to the original window after the window closes, but this feature is not easy to present on the web, and if it's not too hard to actually do it on IE, as long as the parent window window.showModalDialog opens the web window, and the parent window can receive the processing results (Window.returnvalue) as long as the window.returnvalue is set before it closes. There is no problem with this process being synchronized. But Firefox, for security reasons (http://forums.mozine.org/lofiversion/index.php/t2569.html) does not support ShowModalDialog, so at the moment I only know through Window.Open, although not quite the same, but still can simulate the effect. The program is as follows:
Parent.htm
-------------------------------------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<body>
<form id = ' frmmain ' name = ' Frmmain ' >
<button onclick = ' getValue (); ' >getValue</button>
<input type = ' textbox ' value = ' ' id = ' txtValue ' name = ' txtValue ' style = ' display:none '/>
<button id = ' Btnreturn ' name = ' btnreturn ' onclick = ' returnvalue (); ' style = ' display:none ' ></button>
</form>
<script type = ' Text/javascript ' >
<!--//
var winhandler = null;
function GetValue () {
Winhandler = window.open ("child.htm", "Child");
}
Function ReturnValue () {
Alert (document.getElementById (' TxtValue '). Value);
}
-->
</script>
</body>
Child.htm
-------------------------------------------------
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<body>
<button onclick = ' btnClose_Click (); ' >close</button>
<input type = ' textbox ' id = ' txtinput ' value = '/>
<script type = ' Text/javascript ' >
<!--//
var winhandler = null;
function btnClose_Click () {
if (Window.opener!= null) {
var txt = window.opener.document.frmMain.txtValue;
var btn = Window.opener.document.frmMain.btnReturn;
if (txt!= null) {
Txt.value = document.getElementById (' Txtinput '). Value;
}
Btn.click ();
}
Self.close ();
}
-->
</script>
</body>
If the eagle-eyed person should find out that I have btnreturn and txtValue to get the echo back, because the servo has no other way to let the window.open in sync, so it can only be achieved in this weird way ... @_@