How to pass data to parent window from popup window?
up vote
14
down vote
favorite
How can I pass some data or call a function on the parent window from a popup window?
The user will click a link which will open a popup on the same website, once he is finished with the popup, I want it to send the new data back to the parent window, or call a function on the parent window.
javascript jquery popup
add a comment |
up vote
14
down vote
favorite
How can I pass some data or call a function on the parent window from a popup window?
The user will click a link which will open a popup on the same website, once he is finished with the popup, I want it to send the new data back to the parent window, or call a function on the parent window.
javascript jquery popup
What do you mean with popup, do you mean a window opened with _blank?
– sQVe
Aug 26 '12 at 9:51
window.ppopup()
– Click Upvote
Aug 26 '12 at 10:50
add a comment |
up vote
14
down vote
favorite
up vote
14
down vote
favorite
How can I pass some data or call a function on the parent window from a popup window?
The user will click a link which will open a popup on the same website, once he is finished with the popup, I want it to send the new data back to the parent window, or call a function on the parent window.
javascript jquery popup
How can I pass some data or call a function on the parent window from a popup window?
The user will click a link which will open a popup on the same website, once he is finished with the popup, I want it to send the new data back to the parent window, or call a function on the parent window.
javascript jquery popup
javascript jquery popup
asked Aug 26 '12 at 9:47
Click Upvote
95.1k222508688
95.1k222508688
What do you mean with popup, do you mean a window opened with _blank?
– sQVe
Aug 26 '12 at 9:51
window.ppopup()
– Click Upvote
Aug 26 '12 at 10:50
add a comment |
What do you mean with popup, do you mean a window opened with _blank?
– sQVe
Aug 26 '12 at 9:51
window.ppopup()
– Click Upvote
Aug 26 '12 at 10:50
What do you mean with popup, do you mean a window opened with _blank?
– sQVe
Aug 26 '12 at 9:51
What do you mean with popup, do you mean a window opened with _blank?
– sQVe
Aug 26 '12 at 9:51
window.ppopup()
– Click Upvote
Aug 26 '12 at 10:50
window.ppopup()
– Click Upvote
Aug 26 '12 at 10:50
add a comment |
2 Answers
2
active
oldest
votes
up vote
23
down vote
accepted
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()
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
add a comment |
up vote
3
down vote
Here is a fun and easy demo that is heavily inspired by this answer to a similar question (but modified for my own purposes to help investigate the most difficult bug of my career).
Create 2 files (in the same directory) as follows:
parent.html
<button type="button" onclick="popup('popup.html', '', 800, 200);">Add My Card</button>
=>
<span id="retrievedData">No data yet.</span>
<script>
function popup(url, title, width, height)
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
var options = '';
options += ',width=' + width;
options += ',height=' + height;
options += ',top=' + top;
options += ',left=' + left;
return window.open(url, title, options);
function setData(data)
console.log(data);
var strData = JSON.stringify(data);
document.getElementById('retrievedData').innerHTML = strData;
var requestBinUrl = 'http://requestb.in/18u87g81';
window.location.href = requestBinUrl + '?data=' + strData;
</script>
popup.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="popupForm" name="f">
<select id="urlField" name="url">
<option>
http://date.jsontest.com/
</option>
<option>
http://time.jsontest.com/
</option>
<option>
http://md5.jsontest.com/?text=HereIsSomeStuff
</option>
</select>
<div><input type="submit" /></div>
</form>
<script>
$('#popupForm').submit(function(e)
e.preventDefault();
var url = $('#urlField').val();
console.log(url);
$.ajax(
url: url
).then(function(data)
console.log(JSON.stringify(data));
window.opener.setData(data);
window.close();
);
);
</script>
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
23
down vote
accepted
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()
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
add a comment |
up vote
23
down vote
accepted
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()
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
add a comment |
up vote
23
down vote
accepted
up vote
23
down vote
accepted
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()
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()
answered Aug 26 '12 at 9:52
Hoff
17.5k155680
17.5k155680
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
add a comment |
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
will not work in IE when popup window is Cross Domain .
– Salman
Mar 19 '15 at 8:46
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
I see error: Permission denied to access property yourFunc()
– 123qwe
Aug 18 '15 at 10:37
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
stackoverflow.com/a/32617334/470749 is a good example of this working.
– Ryan
Aug 18 '16 at 6:31
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
Old post, but window.parent.document.getElementById('panelControlId') worked for me. It provided the handle to the panel holding this child window, thereby allowing to call pnl.style.display = 'none'; on the panel, thus collapsing it.
– DiligentKarma
May 23 at 7:09
add a comment |
up vote
3
down vote
Here is a fun and easy demo that is heavily inspired by this answer to a similar question (but modified for my own purposes to help investigate the most difficult bug of my career).
Create 2 files (in the same directory) as follows:
parent.html
<button type="button" onclick="popup('popup.html', '', 800, 200);">Add My Card</button>
=>
<span id="retrievedData">No data yet.</span>
<script>
function popup(url, title, width, height)
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
var options = '';
options += ',width=' + width;
options += ',height=' + height;
options += ',top=' + top;
options += ',left=' + left;
return window.open(url, title, options);
function setData(data)
console.log(data);
var strData = JSON.stringify(data);
document.getElementById('retrievedData').innerHTML = strData;
var requestBinUrl = 'http://requestb.in/18u87g81';
window.location.href = requestBinUrl + '?data=' + strData;
</script>
popup.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="popupForm" name="f">
<select id="urlField" name="url">
<option>
http://date.jsontest.com/
</option>
<option>
http://time.jsontest.com/
</option>
<option>
http://md5.jsontest.com/?text=HereIsSomeStuff
</option>
</select>
<div><input type="submit" /></div>
</form>
<script>
$('#popupForm').submit(function(e)
e.preventDefault();
var url = $('#urlField').val();
console.log(url);
$.ajax(
url: url
).then(function(data)
console.log(JSON.stringify(data));
window.opener.setData(data);
window.close();
);
);
</script>
add a comment |
up vote
3
down vote
Here is a fun and easy demo that is heavily inspired by this answer to a similar question (but modified for my own purposes to help investigate the most difficult bug of my career).
Create 2 files (in the same directory) as follows:
parent.html
<button type="button" onclick="popup('popup.html', '', 800, 200);">Add My Card</button>
=>
<span id="retrievedData">No data yet.</span>
<script>
function popup(url, title, width, height)
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
var options = '';
options += ',width=' + width;
options += ',height=' + height;
options += ',top=' + top;
options += ',left=' + left;
return window.open(url, title, options);
function setData(data)
console.log(data);
var strData = JSON.stringify(data);
document.getElementById('retrievedData').innerHTML = strData;
var requestBinUrl = 'http://requestb.in/18u87g81';
window.location.href = requestBinUrl + '?data=' + strData;
</script>
popup.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="popupForm" name="f">
<select id="urlField" name="url">
<option>
http://date.jsontest.com/
</option>
<option>
http://time.jsontest.com/
</option>
<option>
http://md5.jsontest.com/?text=HereIsSomeStuff
</option>
</select>
<div><input type="submit" /></div>
</form>
<script>
$('#popupForm').submit(function(e)
e.preventDefault();
var url = $('#urlField').val();
console.log(url);
$.ajax(
url: url
).then(function(data)
console.log(JSON.stringify(data));
window.opener.setData(data);
window.close();
);
);
</script>
add a comment |
up vote
3
down vote
up vote
3
down vote
Here is a fun and easy demo that is heavily inspired by this answer to a similar question (but modified for my own purposes to help investigate the most difficult bug of my career).
Create 2 files (in the same directory) as follows:
parent.html
<button type="button" onclick="popup('popup.html', '', 800, 200);">Add My Card</button>
=>
<span id="retrievedData">No data yet.</span>
<script>
function popup(url, title, width, height)
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
var options = '';
options += ',width=' + width;
options += ',height=' + height;
options += ',top=' + top;
options += ',left=' + left;
return window.open(url, title, options);
function setData(data)
console.log(data);
var strData = JSON.stringify(data);
document.getElementById('retrievedData').innerHTML = strData;
var requestBinUrl = 'http://requestb.in/18u87g81';
window.location.href = requestBinUrl + '?data=' + strData;
</script>
popup.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="popupForm" name="f">
<select id="urlField" name="url">
<option>
http://date.jsontest.com/
</option>
<option>
http://time.jsontest.com/
</option>
<option>
http://md5.jsontest.com/?text=HereIsSomeStuff
</option>
</select>
<div><input type="submit" /></div>
</form>
<script>
$('#popupForm').submit(function(e)
e.preventDefault();
var url = $('#urlField').val();
console.log(url);
$.ajax(
url: url
).then(function(data)
console.log(JSON.stringify(data));
window.opener.setData(data);
window.close();
);
);
</script>
Here is a fun and easy demo that is heavily inspired by this answer to a similar question (but modified for my own purposes to help investigate the most difficult bug of my career).
Create 2 files (in the same directory) as follows:
parent.html
<button type="button" onclick="popup('popup.html', '', 800, 200);">Add My Card</button>
=>
<span id="retrievedData">No data yet.</span>
<script>
function popup(url, title, width, height)
var left = (screen.width / 2) - (width / 2);
var top = (screen.height / 2) - (height / 2);
var options = '';
options += ',width=' + width;
options += ',height=' + height;
options += ',top=' + top;
options += ',left=' + left;
return window.open(url, title, options);
function setData(data)
console.log(data);
var strData = JSON.stringify(data);
document.getElementById('retrievedData').innerHTML = strData;
var requestBinUrl = 'http://requestb.in/18u87g81';
window.location.href = requestBinUrl + '?data=' + strData;
</script>
popup.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<form id="popupForm" name="f">
<select id="urlField" name="url">
<option>
http://date.jsontest.com/
</option>
<option>
http://time.jsontest.com/
</option>
<option>
http://md5.jsontest.com/?text=HereIsSomeStuff
</option>
</select>
<div><input type="submit" /></div>
</form>
<script>
$('#popupForm').submit(function(e)
e.preventDefault();
var url = $('#urlField').val();
console.log(url);
$.ajax(
url: url
).then(function(data)
console.log(JSON.stringify(data));
window.opener.setData(data);
window.close();
);
);
</script>
edited May 23 '17 at 11:53
Community♦
11
11
answered Aug 18 '16 at 7:10
Ryan
8,639761146
8,639761146
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12129121%2fhow-to-pass-data-to-parent-window-from-popup-window%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What do you mean with popup, do you mean a window opened with _blank?
– sQVe
Aug 26 '12 at 9:51
window.ppopup()
– Click Upvote
Aug 26 '12 at 10:50