This article mainly introduces how to transmit data between windows in the javascript browser. The example analyzes the usage skills of passing parameters between the parent window and the Child window, which is of great practical value, for more information about how to transfer data between javascript browser windows, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
Abstract:
In project development, we often encounter pop-up windows. Some use p to simulate the pop-up effect, some use iframe, and some use the open function provided by window to open a new window. Today we will share with you the last way to use the window. open () function to open a page for data interaction. First, let's take a look:
Principle:
The parent window transmits data to the Child Window through url parameters, and the Child Window transmits data to the parent window through the global function of the parent window.
Code:
Index.html is as follows:
The Code is as follows:
Document
Button
Script
Var test = document. getElementById ('test ');
Test. onclick = function (){
Window. open ('./empty rows 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
Window.html is as follows:
The Code is as follows:
Document
Shanghai Hangzhou
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
Note:A service environment is required.
I hope this article will help you design javascript programs.