Building on the other answers!
The debug version of the code, plus cleanup AND jsbeautifier.org/.
(function() {
var ThisAction = 'https://your.urlgoes.here/build?delay=0sec';
/* A little JSON never hurt anyone */
var ThisPost = {
name: 'ENVIRONMENT',
value: 'production',
name: 'DEPLOYTYPE',
value: 'Incremental',
name: 'BRANCH',
value: 'master',
statusCode: '303',
redirectTo: '.',
json: '{"parameter": [{"name": "ENVIRONMENT", "value": "production"}, {"name": "DEPLOYTYPE", "value": "Incremental"}, {"name": "BRANCH", "value": "master"}], "statusCode": "303", "redirectTo": "."}',
Submit: 'Build'
};
/* Help us locate this function */
console.trace();
/* See what we are looking at */
console.log(document);
var form = document.getElementsByTagName('form')[0];
form.style.visibility = 'hidden';
form.method = 'post';
form.action = ThisAction;
for (var key in ThisPost) {
if (ThisPost.hasOwnProperty(key)) {
input = document.createElement('input');
input.name = key;
input.value = ThisPost[key];
form.appendChild(input);
}
}
/* form.submit(); */
})();
Obviously without the corresponding html, element with tag name 'form' may well not exist... and things are worse if it does. The above demonstrates this well. Note that in chromium javascript: URIs/Bookmarks don't work in a new tab, you must navigate once first. This populates the document object, but even just an javascript:alert('t'); does nothing.
I suggest the following.
(function() {
var ThisAction = 'https://your.urlgoes.here/build?optional=uri_get';
/* A little JSON never hurt anyone */
var ThisPost = {
multiple: 'value',
key: 'pairs',
or: 'JSON like so...',
note: 'the double quotes and last item with NO trailing comma.',
json: '{parameter: [{name: "stuff"}]}'
};
var form = document.createElement('form');
form.style.visibility = 'hidden';
form.method = 'post';
form.action = ThisAction;
for (var key in ThisPost) {
if (ThisPost.hasOwnProperty(key)) {
var input = document.createElement('input');
input.name = key;
input.value = ThisPost[key];
form.appendChild(input);
}
}
document.body.appendChild(form);
form.submit();
})();
Remove debug settings, clean up example input for better clarity of what is expected. Run through http://jscompress.com/ or whatever and get a single line.
!function(){var e="https://your.urlgoes.here/build?optional=uri_get",t={multiple:"value",key:"pairs",or:"JSON like so...",note:"the double quotes and last item with NO trailing comma.",json:'{parameter: [{name: "stuff"}]}'},i=document.createElement("form");i.style.visibility="hidden",i.method="post",i.action=e;for(var o in t)if(t.hasOwnProperty(o)){var a=document.createElement("input");a.name=o,a.value=t[o],i.appendChild(a)}document.body.appendChild(i),i.submit()}();
Edit:
Provide a working example.
In Minneapolis, MN, USA use this to access the Free WiFi ESSID "USIW Free WiFi". After using https://login.usiwireless.com/mplsfree/logon.php?originalurl=www.google.com/ to register an account, they want a credit card for abuse reasons.
Use this to log into the network, with the obvious replacements.
javascript:!function(){var e="https://login.usiwireless.com/mplsfree/logon.pl",o={usernameLogin:"USER",passwordLogin:"PASSWORD",originalurl:"www.google.com/"},n=document.createElement("form");n.style.visibility="hidden",n.method="post",n.action=e;for(var i in o)if(o.hasOwnProperty(i)){var t=document.createElement("input");t.name=i,t.value=o[i],n.appendChild(t)}document.body.appendChild(n),n.submit()}();
Related? Google Chrome: Extention to submit POST/GET requests?
– slhck – 2012-05-18T20:53:08.1431
Depending on your OS, you might want to use
– slhck – 2012-05-18T20:53:55.817curl
to send the POST request from a file insteadalso: How to save a bookmark in Firefox with POST data
– Rich Homolka – 2012-05-19T18:34:08.813Checkout the Greasemonkey extension, available for FF and Chrome. – ott-- – 2012-08-09T12:40:39.930