', '', 'toolbars=0')"> 你能告诉我如何将父窗口重定向到所-6ren">
gpt4 book ai didi

javascript - rails 打开子窗口并打开父窗口

转载 作者:行者123 更新时间:2023-11-30 08:14:07 26 4
gpt4 key购买 nike

单击提交按钮时,我想打开一个子窗口并将父窗口重定向到另一个位置。

为此,我使用了打开子窗口的代码:

<button class="btnBg" onclick="window.open('<%= url_for(:action=>"index") %>', '', 'toolbars=0')">

你能告诉我如何将父窗口重定向到所需位置吗?

最佳答案

最简单的方法是在您的 JavaScript 中为 window.location 赋值(但一定要打开您的新窗口后这样做):

<script type="text/javascript">
function open_and_redirect() {
window.open('<%= url_for(:action=>"index") %>', '', 'toolbars=0');
window.location = 'the new location for the parent window';
}
</script>
<button class="btnBg" onclick="open_and_redirect()">

虽然你不需要使用单独的函数,我这样做只是为了让它更容易阅读。

关于javascript - rails 打开子窗口并打开父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6406760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com