您如何在两个浏览器选项卡/窗口之间进行通信? [英] How do you communicate between two browser tabs/windows?

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

问题描述

我有一个 Web 应用程序,它在新的浏览器窗口/选项卡中作为第二个 Web 应用程序启动.当用户在第二页上提交输入时,我想更新原始页面上的内容.

I have a web application that launches as second web application in a new browser window / tab. I want to update the content on the original page when the user submits their input on the second page.

真实世界示例:

Google 在 Gmail 中使用此行为.撰写新邮件时,如果您单击收件人"链接,它会在新的浏览器窗口中显示您的联系人列表.这使原始撰写电子邮件窗口保持打开状态并处于活动状态以供输入,而用户可以随时从联系人列表中选择电子邮件收件人.当他们提交该窗口时,选定的电子邮件地址会添加到原始撰写窗口的收件人列表中.

Google uses this behavior in Gmail. When composing a new message, if you click the "To" link, it brings up a list of your contacts in a new browser window. This leaves the original compose email window open and active for input while the user can at any time select the email recipients from the list of contacts. When they submit that window, the selected email addresses are added to the recipient list in the original compose window.

这是怎么实现的?我想它可以使用 Ajax 来完成,但理想情况下,该解决方案将避免通过服务器路由所需的往返/编程逻辑.

How is this accomplished? I imagine it could be done using Ajax, but ideally the solution will avoid the round trip / programming logic required to route it via the server.

作为参考,我的技术栈是一个 ASP.NET MVC 应用程序,它启动第二个 ASP.NET MVC 应用程序,其中包含一个 Silverlight 应用程序.两个应用程序都可以/确实使用 jQuery.

For reference, my technology stack for this is an ASP.NET MVC application launching a second ASP.NET MVC application that contains a Silverlight application. Both applications can / do make use of jQuery.

推荐答案

我不认为您指的是两个选项卡.Gmail 正在做的是在弹出窗口和父窗口之间进行通信.

I don't think you mean two tabs. What Gmail is doing is communicating between a pop up and the parent.

假设您使用 JavaScript 打开了一个新窗口.在打开的窗口中,您可以执行以下操作:

So let's say you opened a new window using JavaScript. In the opened window you can do:

opener.someFunction() 传回数据.让我找一个可靠的例子并粘贴它.

opener.someFunction() to pass data back. Let me find a solid example and paste it.

这是一个很好的例子.http://www.javascriptkit.com/javatutors/remote2.shtml

你可以用开瓶器做很多事情.

You can use the opener to do a lot.

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

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