Ways to pass data between JavaScript browser windows _javascript tips

Source: Internet
Author: User

The examples in this article describe a way to pass data between JavaScript browser windows. Share to everyone for your reference. The specific analysis is as follows:

Summary:

In the project development we often encounter the window, some through the div simulation window effect, some through the IFRAME, but also through the window with the open function opened a new window. The last one to share today is to open the page for data interaction through the window.open () function. First look at the effect chart:

Principle:

The parent window passes data to the child window passed through the parameters of the URL, and the child window passes the data to the parent window through the parent window's global function.

Code:
index.html is as follows:

Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Document</title>
<body>
<div id= "Content" ></div>
<button id= "Test" > button </button>
<script>
var test = document.getElementById (' test ');
Test.onclick = function () {
window.open ('./window.html?param1=name&param2=password ', ' _blank ', ' width=960,height=650,menubar=no,toolbar= No,location=no,directories=no,status=no,scrollbars=yes,resizable=yes ');
};
Window.getcontent = function (tx) {
document.getElementById (' content '). innertext = TX;
}
</script>
</body>

Window.html is as follows:

Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Document</title>
<body>
<div id= "Content" ></div>
<select name= "" id= "City" >
<option value= "Shanghai" > Shanghai </option>
<option value= "Hangzhou" > Hangzhou </option>
</select>
<script>
var params = location.href.substring (Location.href.lastIndexOf ('? ') +1). Split (' & ');
document.getElementById (' content '). innertext = params;
var city = document.getElementById (' city ');
City.onchange = function () {
Window.opener.getContent (City.value);
}
</script>
</body>

Note: There needs to be a service environment running here

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.