最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Javascript form submit open new window tab, and then redirect parent page - Stack Overflow

programmeradmin3浏览0评论

When I submit the form I'm trying to open a new window tab and pass the values over into the new window tab. Then I need the parent page to redirect to the next page.

The problem is the form values are not passing to the new window tab. How could I do that with the following code I have right now?

<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("", "_blank");
        window.location = ""
    }

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

When I submit the form I'm trying to open a new window tab and pass the values over into the new window tab. Then I need the parent page to redirect to the next page.

The problem is the form values are not passing to the new window tab. How could I do that with the following code I have right now?

<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./new-tab", "_blank");
        window.location = "https://site./parent-next-page"
    }

    document.getElementById("promo_form_button").onclick = goToUrl;
});
Share Improve this question asked Nov 18, 2013 at 20:32 user23792user23792 431 gold badge1 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Why use window.open when a form can target a new tab/window itself.

HTML:

<form target="_blank" method="get" action="http://google." 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";
    return false;
};

Example:

JSFiddle

发布评论

评论列表(0)

  1. 暂无评论