Javascript 表单提交打开新窗口选项卡,然后重定向父页面

标签 javascript php forms redirect popup

当我提交表单时,我试图打开一个新的窗口选项卡并将值传递到新的窗口选项卡中。然后我需要父页面重定向到下一页。

问题是表单值没有传递到新窗口选项卡。 我如何使用我现在拥有的以下代码来做到这一点?

<form class="form" id="promo_form" method="post">
<input type="text" name="first_name" id="first_name">
<input type="text" name="last_name" id="last_name">
<input type="text" name="zipcode" id="zipcode" maxlength="5">
<button type="submit" id="promo_form_button" class="submit">Continue</button>
</form>


$(document).ready(function($){

var form = document.getElementById("promo_form");

    function goToUrl(){
        window.open("https://site.com/new-tab", "_blank");
        window.location = "https://site.com/parent-next-page"
    }

    document.getElementById("promo_form_button").onclick = goToUrl;
});

最佳答案

为什么要使用 window.open 当表单可以定位到新的选项卡/窗口本身时。

HTML:

<form target="_blank" method="get" action="http://google.com" id="myForm">
    <label for="q">Search: </label><input type="text" id="q" name="q" />
    <input type="submit" value="search" />
</form>

JavaScript:

document.getElementById("myForm").onsubmit = function() {
    window.location.href = "http://www.jsfiddle.net";
    return false;
};

示例:

JSFiddle

关于Javascript 表单提交打开新窗口选项卡,然后重定向父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20057284/

相关文章:

PHP - 是否有机会通过 exec() 运行 GUI 程序?

php - 在 xampp localhost 中使用 PHP 和 htaccess 创建动态子域

javascript - jquery .val() 返回未定义

javascript - 拦截 jQuery 移动页面流,在页面更改之前解析 JSON

javascript - 以编程方式提交帖子表单时,浏览器会中止 iframe 的加载

javascript - 如何在 Odoo 14 中搜索 res.partner 记录

javascript - 在建议列表中单击滚动条时如何使输入不失去焦点

javascript - 在加载的页面中查找值

javascript - 如何使用 HTML 和 JavaScript 检测 iOS 应用何时进入后台

php - 使用 PHP 从远程 JSON 文件检索数据(单个字段)