How JavaScript implements values between pages _javascript tips

Source: Internet
Author: User

This article illustrates the way that JavaScript implements values across pages. Share to everyone for your reference. Specifically as follows:

The questions are as follows:

The,<form> onsubmit event in the A.html page calls a method foo (), which opens the B.html page and passes the arguments to the b.html. Method Foo () requires passing variable arguments to the b.html page, accepting parameter values on the B.html page, but not using server-side technology.

The resolution code is as follows:

The a.html page is as follows:

 
 

Note: You must b.html the page prior to existence.

B.html the code that gets the parameter value is as follows:

b.html part of the 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 "";
}

Add:

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:

 
 

Note: When the b.html page is passed a value, the b.html page must already exist in advance!

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 with your JavaScript programming.

Related Article

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.