Additional requirements:
- Make it generic
- Make it open in a new tab
- Make it open in a new tab with IE11 (tougher still)
- Make it post to an external/different domain
Additional requirements:
The issue is that we cannot POST into a named tab cross domains in IE11.
Instead let's create a file that will build out a form using the query string params.
Now it's just a matter of issuing a get request to that file.
First, create a file called PostRedirect.htm with the following code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="HTMLClient/Scripts/jquery-2.2.4.min.js"></script>
<script type="text/javascript">
//This adapter file allows POSTing to any url via a GET
//Main advantage of this method is that it is IE11 compatible (posting to new named tab is no longer possible in IE11 w/o adjusting the security policy)
//Must pass a param called url
$(document).ready(function () {
//get all the params from the query string
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
var postLaunch = function (url, params) {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", url);
for (var i in params) {
if (params.hasOwnProperty(i)
&& i != 'url' //no need to submit the url param itself
) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = i;
input.value = params[i];
form.appendChild(input);
}
}
document.body.appendChild(form);
form.submit();
};
postLaunch(urlParams['url'], urlParams);
});
</script>
</body>
</html>
Now you simply call the above file with the params of your choice like so:
var params = {
url: 'http://oris.co.palm-beach.fl.us/or_web1/new_sch.asp',
search_by: 'Official Book/Page',
RecSetSize: 100,
PageSize: 20,
search_entry: '24799-0613'
};
window.open('/postredirect.htm?' + $.param(params), '_blank');