How to allow posting form data to a new window in a web app

62 Views Asked by At

I have a form where users can choose between options that changes the file that can be either downloaded or that are presented in another window (such as a PDF that can be printed).

<form action="/pdf" method="post" target="_blank">
    <input type="checkbox" id="show_some_stuff" name="show_some_stuff" value="1"><label for="show_some_stuff">Show some stuff</label>
    (...)
    <input type="submit" name="action" value="Print">
    <input type="submit" name="action" value="Download">
</form>

This works great across browsers. But when this form is accessed in a mobile progressive web application (made available by a web app manifest) the posted values like show_some_stuff and action are not available in the new window.

Is there a way to get the posted values in the new window?

1

There are 1 best solutions below

0
On

As it seems not possible to post values to a new window within web applications, and to preserve the post method on forms when accessed outside a web application, I've added this code so that these forms do not open in a new window inside a web application.

if (window.matchMedia('(display-mode: standalone)').matches) {
    $("form[target='_blank']").each(function() {
        $(this).removeAttr('target');
    });
}

I've been put on the right track by this article by Stefan Judis.