[Html+javascript] Transfer parameters between different page windows

Source: Internet
Author: User
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 ... @_@



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.