Javascript: Post data to new window.

PHOTO EMBED

Mon Aug 29 2022 19:12:43 GMT+0000 (UTC)

Saved by @marcopinero #javascript

openWindowWithPost("http://my.url.address/path", {
    param1: "value1",
    param2: "value2",
    //:
});

function openWindowWithPost(url, data) {
    var form = document.createElement("form");
    form.target = "_blank";
    form.method = "POST";
    form.action = url;
    form.style.display = "none";

    for (var key in data) {
        var input = document.createElement("input");
        input.type = "hidden";
        input.name = key;
        input.value = data[key];
        form.appendChild(input);
    }
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}
content_copyCOPY

Open a new window passing parameters via POST.