How to transmit data between windows in a javascript Browser
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 very useful. For more information, see
This document describes how to transmit data between windows in a javascript browser. 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 div to simulate the pop-up window 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:
<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta charset = "UTF-8">
<Title> Document </title>
</Head>
<Body>
<Div id = "content"> </div>
<Button id = "test"> button </button>
<Script>
Var test = document. getElementById ('test ');
Test. onclick = function (){
Window. open ('./empty rows HTML? Param1 = name parameter m2 = 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>
</Html>
Window.html is as follows:
The Code is as follows:
<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta charset = "UTF-8">
<Title> Document </title>
</Head>
<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>
</Html>
Note: A service environment is required.
I hope this article will help you design javascript programs.