Javascript不能在Facebook上运行iframe [英] Javascript not running on Facebook iframe
问题描述
但是,当它在Facebook应用程序中加载时,负责显示朋友列表的javascript不起作用。虽然库正确加载。
我不知道为什么会这样。可能是一些iframe问题。
以下是JavaScript代码
< script type =text / javascript >
window.fbAsyncInit = function(){
FB.init({appId:'460948667348013',cookie:true});
FB.getLoginStatus(function(response){
if(response.status ==='connected'){
FB.api('/ me',function ){
// alert('你的名字是'+ response.name);
console.log('你的名字是'+ response.name);
init();
$ b)else $(
)else if(response.status ==='not_authorized'){
alert('用户登录到Facebook,但尚未验证您的应用程序');
} else {
alert('该用户未登录到Facebook');
}
});
}
函数init(){
FB.api('/ me',function(response){
$(#username)。html(< img src ='https://graph.facebook.com/+ response.id +/ picture'/>< div>+ response.name +< / div>);
$ (#jfmfs-container)。jfmfs({
max_selected:15,
max_selected_message:{0} of {1} selected,
friend_fields:id,name,last_name ,
pre_selected_friends:[1014025367],
exclude_friends:[1211122344,610526078],
sorter:function(a,b){
var x = a.last_name.toLowerCase ;
var y = b.last_name.toLowerCase();
return((x< y)?-1:((x> y)?1:0));
}
});
$(#jfmfs-container)。bind(jfmfs.friendload.finished,function(){
window.console&& console.log (完成加载!);
});
$(#jfmfs-container)。bind(jfmfs.selection.changed,function(e,data){
window.console&& console.log(changed数据);
});
$(#注销状态)。hide();
$(#show-friends)。show();
});
}
$(#show-friends)。live(click,function(){
var friendSelector = $(#jfmfs-container)。 data('jfmfs');
$(#selected-friends)。html(friendSelector.getSelectedIds()。join(','));
});
函数sendRequest(){
var friendSelector = $(#jfmfs-container)。data('jfmfs');
var sendUIDs = friendSelector.getSelectedIds()。join(',');
//使用FB.ui发送请求
FB.ui({method:'apprequests',
to:sendUIDs,
title:'My Great Invite ',
消息:'看看这个Awesome App!',
},回调);
}
函数回调(响应){
// alert('callback called');
var friendSelector = $(#jfmfs-container)。data('jfmfs');
var sendUIDs = friendSelector.getSelectedIds()。join(',');
var uids = sendUIDs.split(',');
var query =''; (i = 0; i if(i == 0){
query = query +'to ['+ i +'] =' + uids [i];
}
else {
query = query +'& to ['+ i +'] ='+ uids [i];
}
}
console.log(query);
if(response){
// alert('successful');
window.location.assign(/?+查询)
}
else {
alert('failure');
}
}
< / script>
请帮忙!我遇到这个问题。
问题可能是SSL问题。
Facebook在几个月前做了很多变化。
此外,您还需要继续使用Facebook开发人员博客。
所以我将尝试解释我怀疑的几件事。
Facebook上的应用
1a。您的画布网址应该是 https://yoursite.com/yourapplication/
网站
页面标签
-
您的安全画布应该是 https://yoursite.com/yourapplication/
-
您的页面标签网址应为 https://yoursite.com/yourapplication/
-
您的安全网页标签网址应为 https://yoursite.com/yourapplication/
在这种情况下,您将需要SSL证书,因此您可以找到可靠而便宜的数字证书m 此处。
这是必须的任何在Facebook上工作的申请。
希望这将有助于您和他人
I have a django project which is intended for a facebook application. In the project, the invite friends module runs fine in localhost!
But while it is loaded in facebook application, the javascript responsible for displaying the friends list doesn't work. Although the libraries are properly loaded.
I don't know why it is so. May be some iframe problem. Here is the javascript code
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: '460948667348013', cookie: true});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.api('/me', function(response) {
// alert('Your name is ' + response.name);
console.log('Your name is ' + response.name);
init();
});
} else if (response.status === 'not_authorized') {
alert('the user is logged in to Facebook, but has not authenticated your app');
} else {
alert('the user is not logged in to Facebook.');
}
});
}
function init() {
FB.api('/me', function(response) {
$("#username").html("<img src='https://graph.facebook.com/" + response.id + "/picture'/><div>" + response.name + "</div>");
$("#jfmfs-container").jfmfs({
max_selected: 15,
max_selected_message: "{0} of {1} selected",
friend_fields: "id,name,last_name",
pre_selected_friends: [1014025367],
exclude_friends: [1211122344, 610526078],
sorter: function(a, b) {
var x = a.last_name.toLowerCase();
var y = b.last_name.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
});
$("#jfmfs-container").bind("jfmfs.friendload.finished", function() {
window.console && console.log("finished loading!");
});
$("#jfmfs-container").bind("jfmfs.selection.changed", function(e, data) {
window.console && console.log("changed", data);
});
$("#logged-out-status").hide();
$("#show-friends").show();
});
}
$("#show-friends").live("click", function() {
var friendSelector = $("#jfmfs-container").data('jfmfs');
$("#selected-friends").html(friendSelector.getSelectedIds().join(', '));
});
function sendRequest() {
var friendSelector = $("#jfmfs-container").data('jfmfs');
var sendUIDs = friendSelector.getSelectedIds().join(', ');
// Use FB.ui to send the Request(s)
FB.ui({method: 'apprequests',
to: sendUIDs,
title: 'My Great Invite',
message: 'Check out this Awesome App!',
}, callback);
}
function callback(response) {
// alert('callback called');
var friendSelector = $("#jfmfs-container").data('jfmfs');
var sendUIDs = friendSelector.getSelectedIds().join(',');
var uids = sendUIDs.split(',');
var query = '';
for(i=0;i<uids.length;i++){
if(i==0){
query = query + 'to[' + i + ']=' + uids[i];
}
else{
query = query + '&to[' + i + ']=' + uids[i];
}
}
console.log(query);
if(response){
// alert('successful');
window.location.assign("/?"+ query)
}
else{
alert('failure');
}
}
</script>
Please help ! I am stuck with this problem.
The issue may be SSL issues.
Facebook has made many changes in few months ago.
Also you need to keep update with Facebook developer blog.
So I am going to try to explain few things I suspected.
App on Facebook
- Your Canvas Page should be https://apps.facebook.com/yourchoosenname
1a. Your Canvas URL should be https://yoursite.com/yourapplication/
Website
Page Tab
Your Secure Canvas should be https://yoursite.com/yourapplication/
Your Page Tab URL should be https://yoursite.com/yourapplication/
Your Secure Page Tab URL should be https://yoursite.com/yourapplication/
In this case you will need SSL Certificate for site so You can find reliable yet cheap digital certificate from Here .
This mandatory for any Application to work on facebook.
Hope this will help you and others
这篇关于Javascript不能在Facebook上运行iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!