Home >Web Front-end >JS Tutorial >How to transfer data between javascript browser windows_javascript skills

How to transfer data between javascript browser windows_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:19:091297browse

The example in this article describes the method of transferring data between JavaScript browser windows. Share it with everyone for your reference. The specific analysis is as follows:

Summary:

We often encounter pop-up windows during project development. Some use div to simulate the pop-up window effect, some use iframe, and some open a new window through the open function that comes with the window. What I will share with you today is the last way to open the page for data interaction through the window.open() function. First, take a look at the renderings:

Principle:

The parent window passes data to the child window through the url parameters, and the child window passes data to the parent window through the global function of the parent window.

Code:
index.html is as follows:

Copy code The code is as follows:




Document




<script><br>          var test = document.getElementById('test');<br>           test.onclick = function() {<br> 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');<br>         };<br>           window.getContent = function(tx) {<br>                 document.getElementById('content').innerText = tx;<br> }<br> </script>

window.html is as follows:

Copy code The code is as follows:




Document




<script><br>         var params = location.href.substring(location.href.lastIndexOf('?') 1).split('&');<br>            document.getElementById('content').innerText = params;<br>       var city = document.getElementById('city');<br> City.onchange = function() {<br>                 window.opener.getContent(city.value);<br> }<br> </script>

Note: A service environment is required to run here

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn