How to transfer data between javascript browser windows _ javascript skills

Source: Internet
Author: User
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.

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.