问题
I'm attempting to share a link on facebook via url. I get the share to work, however instead of loading the redirectURI, I want to close the popup window. My code:
function fb_share(url) { window.open(url,"share_window","width=400,height=300"); }
...
fb_share('http://www.facebook.com/dialog/feed?app_id=128000000000&link=http%3a%2f%2fwww.facebook.com%2fapps%2fapplication.php%3fid%128000000000%26sk%128000000000&picture=http://www.google.com/images/nav_logo83.png&name=name&description=description&redirect_uri=http%3a%2f%2fwww.facebook.com%2fapps%2fapplication.php%3fid%3d128398017257108%26sk%3dapp_128000000000&display=popup')
回答1:
I wrote a page that can be used as the redirect_uri, which will close popup via javascript: http://www2.highpoint.edu/close_popup.php
View the source to see some simple HTML:
<!doctype html>
<html>
<h3>Thank you!</h3>
<a href="javascript:close();">Close this window</a>
<script type="text/javascript">
close();
</script>
</html>
It works when used as the callback from a Facebook Dialog.
回答2:
Redirected url contains parameter post_id, so you can check on it and close window if you find it:
if (window.location.search.indexOf('post_id') == 1){
window.close();
}
来源:https://stackoverflow.com/questions/7197000/close-facebook-share-popup-after-share-is-complete