花了一整天的時間研究這個問題後,我有一個很好的解決方案,我想分享。與FB.ui()一起使用SDK,我發現我可以通過手動打開自己的彈出框到https://www.facebook.com/dialog/feed來完全避免它。當這樣做時,redirect_uri按預期工作。只要您需要用戶點擊一個按鈕來彈出對話框,就不會觸發彈出式窗口攔截器。
我不認爲這個代碼有任何妥協,如果有的話,它比實際的SDK更容易使用。
我的JavaScript代碼(可以保存爲FacebookFeedDialog.js)看起來是這樣的:
/* by Steven Yang, Feb 2015, originally for www.mathscore.com. This code is free for anybody to use as long as you include this comment. */
function FacebookFeedDialog(appID, linkTarget, redirectTarget) {
this.mParams = {
app_id: appID,
link: linkTarget,
redirect_uri: redirectTarget,
display: "popup"
}
};
/* Common params include:
name - the title that appears in bold font
description - the text that appears below the title
picture - complete URL path to the image on the left of the dialog
caption - replaces the link text
*/
FacebookFeedDialog.prototype.addParam = function(key, value) {
this.mParams[key] = value;
};
FacebookFeedDialog.prototype.open = function() {
var url = 'https://www.facebook.com/dialog/feed?' + encodeCGIArgs(this.mParams);
popup(url, 'feedDialog', 700, 400);
};
/* Takes a param object like this:
{ arg1: "value1", arg2: "value2" }
and converts into CGI args like this:
arg1=value1&arg2=value2
The values and args will be properly URI encoded
*/
function encodeCGIArgs(paramObject) {
var result = '';
for (var key in paramObject) {
if (result)
result += '&';
result += encodeURIComponent(key) + '=' + encodeURIComponent(paramObject[key]);
}
return result;
}
function popup(mylink,windowname,width,height) {
if (!window.focus) return;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
if (!windowname)
windowname='mywindow';
if (!width)
width=600;
if (!height)
height=350;
window.open(href, windowname, 'resizable=yes,width='+width+',height='+height+',scrollbars=yes');
}
下面是一個使用上面的Javascript代碼示例HTML文件:
<HTML>
<BODY>
<SCRIPT type="text/javascript" src="FacebookFeedDialog.js"></SCRIPT>
<SCRIPT>
var dialog = new FacebookFeedDialog(yourAppIDGoesHere,yourDestinationURLGoesHere,yourCloseWindowURLGoesHere);
dialog.addParam('name','This is my title');
dialog.addParam('description','This is the description');
dialog.addParam('picture',yourImageURLGoesHere);
dialog.addParam('caption','This is the caption');
</SCRIPT>
<A href="javascript:dialog.open()">Open facebook dialog</A>
</BODY>
</HTML>
你closeWindow HTML文件可能看起來像這樣:
<SCRIPT>
window.close();
</SCRIPT>
也許這個回答可以幫助你:http://stackoverflow.com/a/2520861/1427942 – Eich 2013-03-02 23:43:00