Monday, May 20, 2024
98
rated 0 times [  100] [ 2]  / answers: 1 / hits: 35058  / 9 Years ago, mon, july 20, 2015, 12:00:00

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:




  1. 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 imitate after sharing callback, but I can't get it when popup is closed.


  2. 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?



More From » facebook-graph-api

 Answers
2

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>

[#65749] Thursday, July 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
admin

Total Points: 468
Total Questions: 103
Total Answers: 103

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;