javascript 从弹出窗口触发父窗口中的点击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3822200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:23:05  来源:igfitidea点击:

Fire a click event in a parent window from a popup

javascriptinternet-explorer

提问by Paul

I can successfully fire a click event in a button on a parent window from a popup in FF and Chrome... however nothing happens in IE. Any ideas?

我可以从 FF 和 Chrome 中的弹出窗口成功地在父窗口上的按钮中触发点击事件......但是在 IE 中没有任何反应。有任何想法吗?

window.opener.document.getElementById(Client ID Of Button).click();

回答by Amr Elgarhy

I think in IE you should write: "self.opener"

我认为在 IE 中你应该写:“ self.opener

I guess the problem is in the window.open function which opened this popup, make sure that there are no spaces in the page name and window name.

我猜问题出在打开此弹出窗口的 window.open 函数中,请确保页面名称和窗口名称中没有空格。

回答by Prashant Lakhlani

this works in FF$(parent.document.getElementById('clientId')).trigger('click');

这适用于 FF$(parent.document.getElementById('clientId')).trigger('click');

回答by Frosty840

The standard answer here in normal GUI-based code is to say that if you have your .click event call a named method, and have all of your actual code inside that method, then it is much easier to have the external object call that named method than it is to have it try and fire a click event.

在基于 GUI 的普通代码中,这里的标准答案是说,如果您让 .click 事件调用一个命名方法,并且在该方法中包含所有实际代码,那么调用命名的外部对象要容易得多方法而不是让它尝试触发点击事件。

Don't know how well this applies to your javascript problem, as it's not my field, but as far as I'm concerned, unless you have a deep and deliberate need to actually have a button be pressed, it's far simpler to call a method.

不知道这如何适用于您的 javascript 问题,因为这不是我的领域,但就我而言,除非您有深切而刻意地需要实际按下按钮,否则调用一个要简单得多方法。

回答by micjohnson

window.opener.document.getElementById(Client ID Of Button).click();

From the above code, just remove the "window." and try again. Its working for me in IE.

从上面的代码中,只需删除“窗口”。然后再试一次。它在 IE 中对我来说有效。

Corrected: opener.document.getElementById(Client ID Of Button).click();

更正: opener.document.getElementById(Client ID Of Button).click();

回答by John Hartsock

I would think that would work but note: the elementID should be in quotes and the dom specifies that the event lives in onClick()

我认为这会起作用,但请注意:elementID 应该用引号引起来,dom 指定该事件存在于 onClick() 中

window.opener.document.getElementById("Client ID Of Button").onClick();

window.opener.document.getElementById("按钮的客户端ID").onClick();

You could also use self.opener

你也可以使用 self.opener

or window.parent or self.parent

或 window.parent 或 self.parent

Hopefully these Ideas help

希望这些想法有帮助