How to transmit data between windows in a javascript Browser

Source: Internet
Author: User

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.

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.