JavaScript implements the method of transferring values between pages, and javascript implements the page
This example describes how to use JavaScript to pass values between pages. Share it with you for your reference. The details are as follows:
The problem is as follows:
On the.html page, the onsubmit event of <form> calls a method foo () to open the B .html page and PASS Parameters to B .html. In method foo (), you need to pass the variable parameters to the B .html page, and accept the parameter values on the B .html page, but you cannot use server-side technology.
The solution code is as follows:
The a.html page is as follows:
<Html>
Note: The B .html page must exist in advance.
B .html:
B .html code
var getQueryString = function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return r[2]; return "";}
Supplement:
Myjs. js code:
function foo(){ var str = "abc"; //document.forms[0].hid.value = str; var frm = window.event.srcElement; frm.hid.value = str; return true; }
A.html code:
<Html>
Note: When you send a value to the B .html page, the B .html page must already exist!
B .html code:
<HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> document.write(decodeURIComponent(location.search.substr(3))); </SCRIPT> </BODY> </HTML>
I hope this article will help you design javascript programs.