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
A string containing a comma-separated list of window features in the form name=value. Boolean values can be set to true using one of: name, name=yes, name=true, or name=n where n is any non-zero integer. These features include options such as the window's default size and position, whether or not to open a minimal popup window, and so forth.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-open-method
JavaScript window.open() Method - GeeksforGeeks
August 5, 2025 - Example 2: In this example, we will open a blank window by passing the URL as an empty string. ... <!DOCTYPE html> <head> <style> body { background-color: #272727; display: flex; justify-content: center; align-items: center; margin-top: 20%; } .main { width: 50%; height: 100%; display: flex; justify-content: center; align-items: center; text-align: center; flex-direction: column; background-color: rgb(82, 82, 82); margin: 10px; font-family: 'Roboto', sans-serif; } .btn { width: 100%; height: 50px; background-color: rgb(29, 29, 29); color: white; font-size: 20px; border: none; cursor: pointer;
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.
🌐
Gitbooks
makersinstitute.gitbooks.io › html-css-js › content › fifth-chapter › the-windowopen-method.html
The Window.open() Method · HTML + CSS + JS
As you can see, the window.open() command can get very long. One solution is to specify the options in a seperate variable, which I call "options." Then your command would look like this: options = "width=100,height=100" NewWindow = window.open("mytest.htm","mywindow",options)
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

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)
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.
🌐
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.
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();
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › met_win_open.asp.html
Window open() Method
var myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window myWindow.document.write("<p>This is 'myWindow'</p>"); // Text in the new window myWindow.opener.document.write("<p>This is the source window!</p>"); // Text in the window that created the new window Try ...
🌐
JavaScript.info
javascript.info › tutorial › frames and windows
Popups and window methods
A name of the new window. Each window has a window.name, and here we can specify which window to use for the popup. If there’s already a window with such name – the given URL opens in it, otherwise a new window is opened.
🌐
Reintech
reintech.io › blog › tutorial-working-with-the-window-open-method
Working with the window.open() Method | Reintech media
February 22, 2023 - 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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-window-open-window-close-method
Javascript Window Open() & Window Close() Method | GeeksforGeeks
August 1, 2024 - It is often used to get user confirmation before an action, returning true if OK is clicked, and false if Cancel is clicked.Syntaxconfirm(message);Parametersmessage: It is the optional string to b ... In HTML, the anchor tag (<a>) is used to ...
🌐
Medium
medium.com › front-end-weekly › passing-data-to-new-window-using-javascript-3637c3a17f76
Passing data to new window using JavaScript | by Abhishek Ankush | Frontend Weekly | Medium
November 5, 2024 - Query-Params: while launching the tab, if we need to pass few parameters to the new window then it can be achieved easily with query-params. // In source/launcher tab window.open('newtab.html?data=value'); // In destination/launched tab const params = new URLSearchParams(window.location.search); const value = params.get('data'); Simplicity: Easy to implement and understand, making it a straightforward choice for passing small amounts of data.
🌐
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 way we can open dynamic popup windows without actually creating Html pages with the ‘post’ method approach.