10

第08课:子窗口交互

 3 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/108729650
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

用 open 方法打开的子窗口也会面临和其他窗口交互的问题,交互无外乎互相传递数据,并接收其他窗口传递过来的数据。

8.1 最简单的传递接收数据

向 open 方法创建的子窗口传递数据有多种方法,其中之一就是使用 BrowserWindowProxy.postMessage 方法,该方法可以向指定的窗口传递任意类型的数据和来源(origin),如果不知来源,可以使用星号 '*' 代替,关于来源是什么,以及如何使用,在后面的内容会详细介绍。

如果只是想向另外的窗口传递数据,需要使用下面的代码。

其中 postMessage 方法的第 1 个参数用于指定要传递的数据,第 2 个参数是来源,一个字符串类型的值,如果不知道来源,可以使用 '*'。

下面的代码在 event.js 文件中,onLoad() 函数是 child.html 的 load() 函数,当 child.html 页面装载完会调用 onLoad() 函数,该函数添加了一个 message 事件的 listener,当使用 postMessage 方法传递数据时,接收数据的页面就


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK