Reputation: 331
I know this type of question have been asked in different ways. But my question is a bit different.
I have the code to do the form submit and the code to open it in a new window. But I have one missing piece in here.
I don't know how to generate the complete URL once i have appended the values to request body.The window.open() expects url as the first parameter and i don't know how to retrieve it.
<script type="text/javascript">
function openviewerSelected() {
var docIds = "{949FFEED-B90B-45DE-BC8A-BDA020D4BCEA}";
if (docIds == null || docIds == "") {
alert("Select atleast one document");
}
else {
var form = document.createElement("form");
form.setAttribute("method", "get");
form.setAttribute("action", "http://aaaa-xxxx.yyyy.com:84/ICNECM/SSOLoginServlet");
form.setAttribute("target", "_blank");
var input3 = document.createElement('input');
input3.type = 'hidden';
input3.name = 'docInfoItems';//'docIds';
input3.value = docIds;
form.appendChild(input3);
var input4 = document.createElement('input');
input4.type = 'hidden';
input4.name = "externalUserId";
input4.value = "abc";
form.appendChild(input4);
document.body.appendChild(form);
var url = "What should be the value?"//document.body.appendChild(form);
var left = (screen.width / 2) - (1000 / 2);
var right = (screen.height / 2) - (600 / 2);
var specsDetails = 'width=1000,height=600,location=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,left=' + left + ',top=' + right + ',scrollbars=yes';
window.open(url, '', specsDetails, '');
form.submit();
debugger;
document.body.removeChild(form);
}
}
</script>
Upvotes: 0
Views: 1861
Reputation: 2030
Ok, judging from your comment
@minitauros, Once I have added the input parameter values to the form, I need to get the Url that is getting generated such that i could pass it the window.open() method. With out the window.open() code, It is opening in a new tab. But i want it to open in a new window .i.e. why the specsDetails.
I would say that you want to open a new window upon form submission instead of a new tab.
If that is the case, consider the following example:
form.addEventListener('submit', function(e) {
e.preventDefault(); // Don't trigger the form submit.
var query_string = input1.name + '=' + input1.value
+ '&' + input2.name + '=' + input2.value
+ '&' + input3.name + '=' + input3.value
+ '&' + input4.name + '=' + input4.value; // etc.
var form_action = this.getAttribute('action');
var url = form_action + '?' + query_string;
// Open your popup.
var left = (screen.width / 2) - (1000 / 2);
var right = (screen.height / 2) - (600 / 2);
var specsDetails = 'width=1000,height=600,location=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,left=' + left + ',top=' + right + ',scrollbars=yes';
window.open(url, '', specsDetails, '');
});
Upvotes: 1