如何在两个浏览器窗口之间进行通信? [英] How to Communicate between two browser windows?

查看:73
本文介绍了如何在两个浏览器窗口之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有父浏览器窗口P.单击按钮时,将打开一个新的浏览器窗口WIN-A。
然后再次按下相同的按钮它应该读取WIN-A窗口的标题并打开WIN-B

I have parent browser window P . on clicking a button a new browser window WIN-A is opened. then again pressing the same button it should read the title of the WIN-A window and open WIN-B

如何使用Javascript实现这一点?

how to achieve this using Javascript?

提前致谢

推荐答案

鉴于:

var myWindow = open("foo.bar");

旧方法:更改窗口对象的名称 property:

Old method: Change the window object's name property:

myWindow.name = "...";
// in foo.bar:
setInterval(someFunctionToCheckForChangesInName, 100);

HTML5方法:调用window对象的 postMessage 方法:

HTML5 method: Call the window object's postMessage method:

myWindow.postMessage("...", "*");
// in foo.bar:
(window.addEventListener || window.attachEvent)(
  (window.attachEvent && "on" || "") + "message", function (evt) {
    var data = evt.data; // this is the data sent to the window
    // do stuff with data
  },
false);

这篇关于如何在两个浏览器窗口之间进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆