Pass Variable To A Popup Window Using Javascript
Solution 1:
use window.opener
From Mozilla Developer Network: When a window is opened from another window, it maintains a reference to that first window as window.opener. If the current window has no opener, this method returns NULL.
https://developer.mozilla.org/en-US/docs/Web/API/window.opener
This way you can have on your original window a callback, and you can notify the window it's load and ready, rather than wait a random delay...
you add a function on the original window:
window.popupReady = function (callbackToPopup) {
callbackToPopup(newData);
}
then the popup can tell the parent window it's ready and pass it a callback to update it with data..
and on the popup try something like:
window.dataReady(newData)
{
alert(newData);
}
document.addEventListener("load", function() { window.opener.popupReady (dataReady); }
I didn't test this code, but I would take such a path as this should ensure the popupWindow is ready for you and is along the spirit of JavaScript.
Solution 2:
In your onclick
attribute you pass '90' to the function, but the function isn't set up to take an argument. So, change the first line of your function like this:
functionwriteToWindow(data) {
You don't need the global var data;
or the local var k = data;
, so get rid of them.
And instead of + k +
write + data +
.
That should do get your data passed.
Solution 3:
Use this code, it works perfectly in all browsers .
#desc = parent text area id#desc_textarea = popup $("#desc_textarea").val(window.opener.$("#desc").val())
Post a Comment for "Pass Variable To A Popup Window Using Javascript"