jQuery控件从子窗口的父窗口 [英] Jquery control parent window from child window

查看:100
本文介绍了jQuery控件从子窗口的父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个项目的一些想法,其中一个需要以某种方式在2个不同的浏览器页面/窗口/选项卡之间进行通信.我的目标是这样:

I'm playing around with a few ideas for a project, and one of them needs to somehow have communication between 2 different browser pages/windows/tabs. My goal is this:

我有一个主页,该主页具有打开新标签页/窗口的链接.在该窗口中,可以选择导航"主页的一部分.据我所知,问题在于打开的窗口之间没有任何物理联系(并且孩子无法访问父"窗口上的句柄).

I have a main page that has a link that opens a new tab/window. In that window, there is the choice to 'navigate' a part of the main page. The issue is, to my knowledge, there are no physical ties between open windows (and no handle on the 'parent' window accessible by the child).

我一直在尝试使用opener来引用父窗口,但是函数和元素没有响应我对子窗口的调用.

I've been trying to use opener to reference the parent window, but functions and elements are not responding to my calls from the child.

子窗口/其他窗口是否可以访问父窗口上的元素/功能?

Is there any way for a child/other window to access elements/functions on a parent window?

我试图避免使用模拟的制表符/框架(这很容易仅引用父级或窗口元素来实现目标).

I'm attempting to avoid using simulated tabs/frames (which would be easy enough to just reference the parent, or window element to accomplish the goal).

推荐答案

是的,实际上是可行的.如果在JavaScript中使用window.open(),则可以使用window.opener.并提交通常会发出的任何请求.喜欢:

Yes, actually that is possible. If you use window.open() in JavaScript, you can use window.opener. and submit whatever requests you would normally make. Like:

window.opener.document.getElementById('id').innerHTML = "hello";

或使用jQuery

$(window.opener.document).find('#tableInParent').html("hello");

在此处了解更多信息: http://wisercoder.com/javascript-jquery-parent-windows/

Read more here: http://wisercoder.com/javascript-jquery-parent-windows/

此处的JSFIDDLE

我希望这会有所帮助!

这篇关于jQuery控件从子窗口的父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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