admin管理员组文章数量:1181872
javascript
document.querySelector('#share').onclick = function () {
var popup = window.open('.php?u=', '', "width=400, height=400");
popup.onbeforeunload = function() {
alert('unload');
}
return false;
};
HTML
<a id="share" href="#">share</a>
Two things:
I want to do something after user finish the facebook share thing, if I share the page by open window the window will be auto close after everything is done, so I want to use
beforeload
event to imitateafter sharing callback
, but I can't get it when popup is closed.If user just turn off the window or cancel sharing will also trigger the event, so it's not the best solution, is there any facebook sharing successful callback api?
javascript
document.querySelector('#share').onclick = function () {
var popup = window.open('http://www.facebook.com/sharer/sharer.php?u=http://www.google.com', '', "width=400, height=400");
popup.onbeforeunload = function() {
alert('unload');
}
return false;
};
HTML
<a id="share" href="#">share</a>
Two things:
I want to do something after user finish the facebook share thing, if I share the page by open window the window will be auto close after everything is done, so I want to use
beforeload
event to imitateafter sharing callback
, but I can't get it when popup is closed.If user just turn off the window or cancel sharing will also trigger the event, so it's not the best solution, is there any facebook sharing successful callback api?
3 Answers
Reset to default 33Solved this problem with setInterval
:
document.querySelector('#share').onclick = function () {
var popup = window.open('http://www.facebook.com/sharer/sharer.php?u=http://www.google.com', '', "width=400, height=400");
var popupTick = setInterval(function() {
if (popup.closed) {
clearInterval(popupTick);
console.log('window closed!');
}
}, 500);
return false;
};
I've made a small javascript plugin for that functionality and without the limitation of same domain.
It has some more functionality, like ability to open the popup with a post and other small stuff.
Hope people looking for an answer find it useful.
https://github.com/enhancv/popup-tools
It does not work due to cross domain calls. To get the unload event you need to call a popup instead, which has the wanted url in an iframe.
document.querySelector('#share').onclick = function(){
var popup = window.open('popup.html', '', "width=400, height=400");
popup.onbeforeunload = function(){
console.log('unload');
}
};
popup.html
<iframe src = 'http://www.facebook.com/sharer/sharer.php?u=http://www.google.com'></iframe>
本文标签: javascriptHow to detect popup window close eventStack Overflow
版权声明:本文标题:javascript - How to detect popup window close event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738206201a2068622.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论