gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:57 25 4
gpt4 key购买 nike

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

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

<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/

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