How to reload http window.opener from https popup?
I have an http window which opens a secure popup to submit a form to a 开发者_JAVA百科third party web site. After the popup is closed, I would like to reload the opener so that it reflects the results of the form submission.
Since the opener and the popup use different protocols (http and https), I can't do it in the straightforward way (window.opener.location.reload()). Is there another way? Do I have to venture into JSONP?
Kludgy way: set timeout to check if opened popup was closed.
function checkClosed(){
if(new_win.closed){
alert('Window was closed');
}
else{
window.setTimeout(checkClosed,1000);
}
}
new_win = window.open('about:blank');
window.setTimeout(checkClosed,1000);
I know that this is a super old question, but I found a better way to do this: Cross-document messaging:
$('a#popup').on('click', function(event) {
event.preventDefault();
$this = $(this);
authenticationWindow = window.open($this.href, 'authenticationPopup');
});
window.addEventListener('message', function (evt) {
// simplified, should check for matching event.origin
if (event.data == 'OK' && event.origin == window.location.protocol+'//'+window.location.host) {
authenticationWindow.close();
}
});
While from the pop up (of course if you control it, at least the last page) you need this:
opener.postMessage('OK', window.location.protocol+'//'+window.location.host);
This will close the popup, and allows you to do other stuff as well, like update data via Ajax or reload the page.
精彩评论