jquery open page in a tab and pass some POST values
I would suggest creating an invisible form in your HTML like this:
<form id="invisible_form" action="new_window.php" method="post" target="_blank">
<input id="new_window_parameter_1" name="parameter" type="hidden" value="default">
</form>
..and then submitting it via jQuery:
$('#new_window_parameter_1').val('value');
$('#invisible_form').submit();
Here is a sample how to submit a hidden form via POST:
function submit_post_via_hidden_form(url, params) {
var f = $("<form target='_blank' method='POST' style='display:none;'></form>").attr({
action: url
}).appendTo(document.body);
for (var i in params) {
if (params.hasOwnProperty(i)) {
$('<input type="hidden" />').attr({
name: i,
value: params[i]
}).appendTo(f);
}
}
f.submit();
f.remove();
}
And to use it:
submit_post_via_hidden_form(
'some link',
{
val1: val1,
val2: val2
}
);
Lite version with simple array compatibility:
var url = 'myurl.html';
var params = {
inputId: 'somevalue',
itemArray: ['as','a','example']
};
var f = $("<form target='_blank' method='POST' style='display:none;'></form>").attr({
action: url
}).appendTo(document.body);
for (var i in params) {
if (params.hasOwnProperty(i)) {
if($.isArray(params[i])) {
for (var j in params[i]) {
$('<input type="hidden" />').attr({
name: i + '[]',
value: params[i][j]
}).appendTo(f);
}
} else {
$('<input type="hidden" />').attr({
name: i,
value: params[i]
}).appendTo(f);
}
}
}
f.submit();
f.remove();