Murtaza
Murtaza

Reputation: 3065

Can we redirect a page to new window with submit button

Hi i have a form on my page, in asp.net, my form is hidden, it open in lightbox on click of a link on the page.

lightbox has a div with HTML form POST method and action to some URL, on click of submit button inside the form i am redirect to the action passed above, but i want to redirect on new window instead of same window. How can i achieve this. not i cannot change the action and form Post method since it is third party HTML for some functionality. If i change the Form HTML my functionality does not work.

If possible i can try to change my question please let me know.. if you need something more than this information...

Upvotes: 2

Views: 4692

Answers (2)

batbaatar
batbaatar

Reputation: 5468

I don't why Sameera Thilakasiri's solution is not working. But please try this:

First please refer to this page: JavaScript post request like a form submit

You can do form submission with form object. If you can get the current values of forms and assign it to new form you are creating, it might work. Of course you should add the function name

function post_to_url(path, params, method) {
    method = method || "post"; 

     var form = document.createElement("form");
        form.setAttribute("method", method);
        form.setAttribute("action", path);
        form.setAttribute("target", "_blank");
    ...

        document.body.appendChild(form);
        form.submit();
        return false;
}

And change

<form action="form_action.asp" method="post" target="_blank" onsubmit="javascript:post_to_url(path, params, method)"> 

Upvotes: 0

Sameera Thilakasiri
Sameera Thilakasiri

Reputation: 9508

Try this example,

  <form action="form_action.asp" method="post" target="_blank"> 

Add the attribute target="_blank"

Upvotes: 2

Related Questions