单击提交按钮时,我想打开一个子窗口并将父窗口重定向到另一个位置。
为此,我使用了打开子窗口的代码:
<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/