Home  >  Article  >  Web Front-end  >  Sharing three methods of passing values ​​in javascript static pages_javascript skills

Sharing three methods of passing values ​​in javascript static pages_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:15:481167browse

1: JavaScript Static Page Value Transfer URL Article
You can pass the value through the URL. Connect the information to be transferred to the URL.
Post. htm

Copy code The code is as follows:






Read.htm

Copy code The code is as follows:


<script><br>String.prototype.getQuery = function(name)<br>{<br>var reg = new RegExp("(^|&)" name "=([ ^&]*)(&|$)");<br>var r = this.substr(this.indexOf("?") 1).match(reg);<br>if (r!=null) return unescape(r[2]); return null;<br>}<br>var str ="www.jb51.net/index.htm?a=1&b=1&c=test test";<br>alert(str.getQuery ("a"));<br>alert(str.getQuery("b"));<br>alert(str.getQuery("c"));<br></script>

Advantages: Convenient to obtain values. Can cross domains.
Disadvantages: Value length is limited

2: Cookies for JavaScript Static Page Value Transfer
Cookies are browsers that store a small amount of named data.
It is associated with a specific web page or website Together.
Cookies are used to provide memory to the browser,
so that scripts and server programs can use input data from one page to another page.
Post.htm

Copy code The code is as follows:


< input type="button" value="Post">

Read.htm

Copy code The code is as follows:


Advantages: It is convenient to obtain values. As long as window.opener points to the parent window, you can access all objects. Not only can you access the value, but you can also access the methods of the parent window. There is no limit to the value length.
Disadvantages: Two The window must have a relationship. It is a window opened using window.open. It cannot cross domains.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn