Quickest way to pass data to a popup window I created using window.open()?
Due to security restrictions it is super easy only if the parent window and the popup are from the same domain. If that is the case just use this:
// Store the return of the `open` command in a variable
var newWindow = window.open('http://www.mydomain.com');
// Access it using its variable
newWindow.my_special_setting = "Hello World";
In the child (popup) window, you could access that variable like this:window.my_special_setting
Was there something specific you wanted to do past that? How to pass data to parent window from popup window?
The window.opener object is what you're looking for, used it from within your popup like so to call the a function of the parent window:
window.opener.yourFunc()
Passing text to a popup window opened in a JS function
You could pass basic data in the url hash, change your JS to
var popup=window.open('popup.html#MY_DATA', 'myWindow','width=500,height=500');
and then in the popup.html page you can access the it by looking into the location.hash variable:window.location.hash
//This will be "#MY_DATA"
How to pass data from Parent window to pop-up window
Try this :
parent window js : window.open("popup.html", "popup",'toolbar = no, status = no beforeShow');
children/pop-up window js : window.opener.document.getElementById("parent_window_id").innerHTML;
Normally you can not access any function or data of parent window from Child/popup window unless you use window.opener = parent window (this is just reference of parent window) and then get any id, function or data(innerHTML) How pass data to popup window which created used div
Create the popup window this way
var childWindow=window.open("windowUrl");
You then either need to create a function in the child window that sets the name, price, and chosen row and then call that function this way in the parent window. childWindow.setterFunction(name,price,chosenRow);
Or, you could create global variables (not recommended ) in the child window for name, price, and chosen row and then set them from the parent window like this childWindow.Name =name;
childWindow.Price = price;
childWindow.chosenRow = chosenRow;
Pass value to popup window
You can pass ProductName
and ProductPrice
as query string to new location
, then use search
, .split()
, while
loop to set properties, values to an object.
function makeOrder(name, price){
window.open("/user/makeOrder?ProductName=" + name + "&ProductPrice=" + price,""
,"height=250,width=400,status=no,location=no,toolbar=no,directories=no,menubar=no");
}
At newly opended window
var params = location.search.split(/\?|=|&/).filter(Boolean);
var obj = {}, i = 0;
while (i < params.length) {
obj[params[i]] = params[++i];
++i;
}
console.log(obj)
Javascript window.open pass values using POST
I used a variation of the above but instead of printing html I built a form and submitted it to the 3rd party url:
var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "http://www.url.com/map.php";
var mapInput = document.createElement("input");
mapInput.type = "text";
mapInput.name = "addrs";
mapInput.value = data;
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
map = window.open("", "Map", "status=0,title=0,height=600,width=800,scrollbars=1");
if (map) {
mapForm.submit();
} else {
alert('You must allow popups for this map to work.');
}
Related Topics
When Do I Need to Specify the JavaScript Protocol
Updating Svg Element Z-Index with D3
Using the Haversine Formula in JavaScript
Why Can't I Assign a New Value to "This" in a Prototype Function
Why "This" Is Undefined Inside a Fat Arrow Function Definition
Basic Ajax Send/Receive with Node.Js
Jquery "On Create" Event for Dynamically-Created Elements
Can Jquery Provide the Tag Name
How to Add My Own Methods to HTMLelement Object
JavaScript Array Concat Not Working. Why
What Is the Point of Void Operator in JavaScript
Why Let and Var Bindings Behave Differently Using Settimeout Function
In JavaScript, Can You Extend the Dom
Ng-Model Does Not Update Controller Value
Wait Till a Function with Animations Is Finished Until Running Another Function