Passing data between JavaScript browser windows

Source: Internet
Author: User

Summary:

In the development of the project, we often encounter pop-up windows, some through the div simulation of the effect of the window, some through the IFRAME, but also through the window's own open function opens a new window. What we're sharing today is the last one to open the page with the window.open () function to interact with the data. First look at the following:

Principle:

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

Code:

Index.html

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body>    <DivID= "Content"></Div>    <ButtonID= "Test">Button</Button>    <Script>        varTest=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></HTML>

Window.html

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body>    <DivID= "Content"></Div>    <Selectname=""ID= "City">        <optionvalue= "Shanghai">Shanghai</option>        <optionvalue= "Hangzhou">Hangzhou</option>    </Select>    <Script>        varparams=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: to have a service environment


Other wonderful articles

Android Learning Notes ($) Android Options Menu and submenu (submenu) Android Learning note (notification) features and usage of Android learning Note (Android) using listeners to listen to menu events Android Learning notes (+) Android Create a single-selection menu and a check menuAndroid Learning Notes (Android) setting activity associated with menu itemsAndroid Learning Notes (Android context menu)

more about Android Development articles

Passing data between JavaScript browser windows

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.