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 target parameter determines which window or tab to load the resource into, and the windowFeatures parameter can be used to control to open a new popup with minimal UI features and control its size and position.
🌐
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.
Discussions

Javascript window.open() passing variables
The value in your window.open() is not for passing variables. That is to set the window parameters https://developer.mozilla.org/en-US/docs/Web/API/Window/open#parameters . Just use query string parameters. Something like this const params = new URLSearchParams(); params.set("a", 1); params.set("b", 2); const w = window.open(`myfile.html?${params.toString()}`); More on reddit.com
🌐 r/learnjavascript
7
1
August 18, 2024
How can I pass a parameter to a window.open command
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 ... More on community.spiceworks.com
🌐 community.spiceworks.com
2
3
December 7, 2021
html - javascript window.open and adding parameters - Stack Overflow
I'm having some issues with my javascript link I have a hidden input fields with the name "domein" I'm having the following div with a onclick script More on stackoverflow.com
🌐 stackoverflow.com
Opening a window using windows.open() in Javascript - Stack Overflow
I get it now...so the height and ... the 2nd parameter...thank you 2018-04-08T09:44:36.953Z+00:00 ... window.open is rather browser specific, you need to test it. There are ethical problems surrounding its use so some attributes do not operate in newer browsers because of malicious javascript ... More on stackoverflow.com
🌐 stackoverflow.com
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();

}
🌐
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.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-open-window-close-method
Javascript Window Open() & Window Close() Method - GeeksforGeeks
August 5, 2025 - The Javascript Window.Open() method is used to open the web pages into a new window or a new tab. It depends on the browser settings and the values assigned to the parameter.
🌐
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.
🌐
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> ...
🌐
Coderanch
coderanch.com › t › 546661 › languages › Modifying-window-open-parameters
Modifying the window.open() parameters (HTML Pages with CSS and JavaScript forum at Coderanch)
July 25, 2011 - 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.
🌐
Reintech
reintech.io › blog › tutorial-working-with-the-window-open-method
Working with the window.open() Method | Reintech media
January 13, 2026 - The window.open() method is a powerful function in JavaScript used to open new browser windows or tabs and manipulate existing ones. It accepts three parameters: URL, window name, and window features.
🌐
StudySection
studysection.com › home › open a popup window with a window.open() passing parameters as ‘post’
Open a popup with a window.open passing parameter - SS Blog
January 13, 2023 - This is required especially in cases when dealing with third-party links*/ let windowExists = false; if (popupDocWindow && popupDocWindow!=null) { windowExists = true; } if (windowExists == true) { popupDocWindow.close(); } else { // apply any required code } popupDocWindow = window.open('', windowName, windowProperty); popupDocWindow.document.write(popupSubmitWindowForm); To achieve on-the-fly form submit, we can simply create a form Html with input elements containing required post data and script that triggers the form submit action. Now this dynamic Html and javascript content can be written to the newly opened popup window from the parent window using javascript.
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();
🌐
Spiceworks
community.spiceworks.com › programming & development
Passing form parameters using window.open()… - Programming & Development - Spiceworks Community
February 19, 2007 - Hello Frens, In my project, After entering the username, password and a click on submit button a popup window should open and this username and password shud be passed to that window this is my code : Username : Password : i am not able to pass username and password with the above code if i use form action=““xyz.jsp”” methos=““post”” target=““new”” i can pass username and password, but i am not able to set the window properties like width, height etc… please help me out thanx in advance…
🌐
Javatpoint
javatpoint.com › javascript-window-open-method
JavaScript Window open method - javatpoint
April 28, 2021 - JavaScript Window open method with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
🌐
SitePoint
sitepoint.com › javascript
Passing value in window.open - JavaScript - SitePoint Forums | Web Development & Design Community
February 10, 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…