if you want to pass POST variables, you have to use a HTML Form:

<form action="http://localhost:8080/login" method="POST" target="_blank">
    <input type="text" name="cid" />
    <input type="password" name="pwd" />
    <input type="submit" value="open" />
</form>

or:

if you want to pass GET variables in an URL, write them without single-quotes:

http://yourdomain.com/login?cid=username&pwd=password

here's how to create the string above with javascrpt variables:

myu = document.getElementById('cid').value;
myp = document.getElementById('pwd').value;
window.open("http://localhost:8080/login?cid="+ myu +"&pwd="+ myp ,"MyTargetWindowName");

in the document with that url, you have to read the GET parameters. if it's in php, use:

$_GET['username']

be aware: to transmit passwords that way is a big security leak!

Answer from Roman Abt on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN
The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name. ... A string indicating the URL or path of the resource to be loaded. If an empty string ("") is specified or this parameter ...
Top answer
1 of 7
15

if you want to pass POST variables, you have to use a HTML Form:

<form action="http://localhost:8080/login" method="POST" target="_blank">
    <input type="text" name="cid" />
    <input type="password" name="pwd" />
    <input type="submit" value="open" />
</form>

or:

if you want to pass GET variables in an URL, write them without single-quotes:

http://yourdomain.com/login?cid=username&pwd=password

here's how to create the string above with javascrpt variables:

myu = document.getElementById('cid').value;
myp = document.getElementById('pwd').value;
window.open("http://localhost:8080/login?cid="+ myu +"&pwd="+ myp ,"MyTargetWindowName");

in the document with that url, you have to read the GET parameters. if it's in php, use:

$_GET['username']

be aware: to transmit passwords that way is a big security leak!

2 of 7
4

Please find this example code, You could use hidden form with POST to send data to that your URL like below:

function open_win()
{
    var ChatWindow_Height = 650;
    var ChatWindow_Width = 570;

    window.open("Live Chat", "chat", "height=" + ChatWindow_Height + ", width = " + ChatWindow_Width);

    //Hidden Form
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", "http://localhost:8080/login");
    form.setAttribute("target", "chat");

    //Hidden Field
    var hiddenField1 = document.createElement("input");
    var hiddenField2 = document.createElement("input");

    //Login ID
    hiddenField1.setAttribute("type", "hidden");
    hiddenField1.setAttribute("id", "login");
    hiddenField1.setAttribute("name", "login");
    hiddenField1.setAttribute("value", "PreethiJain005");

    //Password
    hiddenField2.setAttribute("type", "hidden");
    hiddenField2.setAttribute("id", "pass");
    hiddenField2.setAttribute("name", "pass");
    hiddenField2.setAttribute("value", "Pass@word$");

    form.appendChild(hiddenField1);
    form.appendChild(hiddenField2);

    document.body.appendChild(form);
    form.submit();

}
🌐
W3Schools
w3schools.com › jsref › met_win_open.asp
Window open() Method
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-open-method
JavaScript window.open() Method - GeeksforGeeks
August 5, 2025 - If an empty string is provided then it will open a blank new tab. windowName: It can be used to provide the name of the window. This is not associated with the title of the window in any manner. It can accept values like _blank, _self, _parent, etc. windowFeatures: It is used to provide features to the window that will open, for example, the dimension and position of the window.
Top answer
1 of 2
2

The simple answer is yes. But make it a function that calculates those values when called. In other words:

let helpDimensions=function (w,h,l,t) {
return "width="+(w||findWidth())+", height="+h||findHeight()+", left="+(l||findLeft())+", top="+(t||findTop());
}
//this lets you pass a width, height, left, and top to override the calculated dimensions.
/*you will need to establish a findWidth(), findHeight(), findLeft(), and findTop functions or include them inline like:
return "width="+window.innerWidth*0.8+", height="+window.innerHeight*0.8+", left="0.1*window.innerWidth+", top="+window.innerHeight*0.1;
*/

/*then just perform function call like this:
window.open(url, title, helpDimensions()); to calculate the correct dimensions each time
*/

Also, establish a click handler on an element like this:

$("#someelement").on("click", function (e) {
e.preventDefault();
window.open("test.html","test", helpDimensions());
});

using jquery to set the onClick attribute of an existing element is a bad idea.
Also make sure that all of this is enclosed in an Immediate Invoked Injection Function or IIIF like this:

$(function () {
//define your helpDimensions function to calculate dimensions dynamically
//define your click event handler
});

//this ensures that it is not called until everything is loaded.

Hope this helps.
Here’s a great website for calculating dimensions and working with the window reference object to ensure that your content goes into the correct window (which can be reused if needed):

xtf.dk

Center a new popup window even on dualscreen with javascript

function PopupCenter(url, title, w, h) { // Fixes dual-screen position Most browsers Firefox var dualS...

2 of 2
3

I have a window.open command as follows:

$('#documentation_href').attr('onclick', "window.open('../help.php#Sale_Records','Help','width=1800,height=900,top=100,left=200')");

This works fine on my desktop but I’m sure the width and height will be too big for some computers so I would like to vary the parameters depending on the screen height.

I’ve successfully got some code to calculate the ideal values and have placed them into a parameter - the values vary depending on the screensize.

I’ve set this parameter as follows:

help_dimensions = 'width=' + help_width + ',height=' + help_height + ',left=' + help_left + ',top=' + help_top;

But I would like to know how I can use the parameter help_dimensions in my window.open command instead of the hardcoded values.

@nrgfusion

🌐
Educative
educative.io › answers › what-is-the-windowopen-method-in-javascript
What is the window.open() method in JavaScript?
If no URL is indicated, a blank browser window will be opened. name: The name parameter is like the target attribute.
🌐
Arai-a
arai-a.github.io › window-open-features
window.open with features
features parameter of window.open interacts with where the newly created browsing context is opened.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 546661 › languages › Modifying-window-open-parameters
Modifying the window.open() parameters (HTML Pages with CSS and JavaScript forum at Coderanch)
Hi folks, Im kind a new to Javascript . Im trying to use a JS function to call throw a pop as below Here IM being able to set the height ,width,top attributes correctly but none of the other parameters seem to work like resizable =no,or location =no. Why could this be happening? Learning and Learning!-- Java all the way! ... Modern day browsers have options built in to prevent the window from hiding those.
Top answer
1 of 10
147

Instead of writing a form into the new window (which is tricky to get correct, with encoding of values in the HTML code), just open an empty window and post a form to it.

Example:

<form id="TheForm" method="post" action="test.asp" target="TheWindow">
<input type="hidden" name="something" value="something" />
<input type="hidden" name="more" value="something" />
<input type="hidden" name="other" value="something" />
</form>

<script type="text/javascript">
window.open('', 'TheWindow');
document.getElementById('TheForm').submit();
</script>

Edit:

To set the values in the form dynamically, you can do like this:

function openWindowWithPost(something, additional, misc) {
  var f = document.getElementById('TheForm');
  f.something.value = something;
  f.more.value = additional;
  f.other.value = misc;
  window.open('', 'TheWindow');
  f.submit();
}

To post the form you call the function with the values, like openWindowWithPost('a','b','c');.

Note: I varied the parameter names in relation to the form names to show that they don't have to be the same. Usually you would keep them similar to each other to make it simpler to track the values.

2 of 10
78

Since you wanted the whole form inside the javascript, instead of writing it in tags, you can do this:

let windowName = 'w_' + Date.now() + Math.floor(Math.random() * 100000).toString();
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "openData.do");

form.setAttribute("target", windowName);

var hiddenField = document.createElement("input"); 
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "message");
hiddenField.setAttribute("value", "val");
form.appendChild(hiddenField);
document.body.appendChild(form);

window.open('', windowName);

form.submit();
🌐
Mozilla Support
support.mozilla.org › en-US › questions › 1288277
Firefox 76.0 javascript window.open() parameters ignored ...
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Gitbooks
makersinstitute.gitbooks.io › html-css-js › content › fifth-chapter › the-windowopen-method.html
The Window.open() Method · HTML + CSS + JS
The 3 parameters are: A URL so that the window contains a specific HTML document. ... A set of options for the window's appearance, including height and width. For example, let's say I created a page called mytest.htm. It might be as simple as this: <HTML> <HEAD> <TITLE>Test Page </TITLE> </HEAD> ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-open-window-close-method
Javascript Window Open() & Window Close() Method - GeeksforGeeks
August 5, 2025 - If this parameter returns true then URL replaces the current document in the history list and if returns false then URL creates a new entry in the history list. Return Value: This method creates a new window. Window.close(): This method is used to close the window which is opened by the window.open() method.
🌐
Javatpoint
javatpoint.com › javascript-window-open-method
JavaScript Window open method - javatpoint
JavaScript Window open method with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
🌐
JavaScript.info
javascript.info › tutorial › frames and windows
Popups and window methods
If there is no 3rd argument in the open call, or it is empty, then the default window parameters are used.
🌐
SitePoint
sitepoint.com › javascript
Passing value in window.open - JavaScript - SitePoint Forums | Web Development & Design Community
February 13, 2009 - passing values with url alert(document.Form1.pid.value ) window.open(‘test.aspx?id=" + document.Form1.pid.value ‘,’’,‘scrollbars=yes,resizable=yes,width=800,height=400’); i have made this function and want to pass…