Javascript FBAPI对画布宽度的调用始终为零
我正在使用Facebook图形API(javascript-one) 我试图使用函数FB.canvas.getPageInfo()[“clientWidth”]获取画布大小 但它总是返回零,为什么 也许是我调用函数的时候?也许它的意思是零,但我不这么认为,因为如果它是零,我将无法在画布中看到我的HTML,因为宽度是零,对吗 我的代码:Javascript FBAPI对画布宽度的调用始终为零,javascript,html,facebook,facebook-graph-api,Javascript,Html,Facebook,Facebook Graph Api,我正在使用Facebook图形API(javascript-one) 我试图使用函数FB.canvas.getPageInfo()[“clientWidth”]获取画布大小 但它总是返回零,为什么 也许是我调用函数的时候?也许它的意思是零,但我不这么认为,因为如果它是零,我将无法在画布中看到我的HTML,因为宽度是零,对吗 我的代码: <html> <head> </head> <body> <div id="fb-root"&g
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function()
{
FB.init( {appId: 'MYAPPID', status: true, cookie: true, xfbml: true} );
};
(function()
{
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
<script type="text/javascript">
<!--
alert( FB.Canvas.getPageInfo()["clientWidth"] ); // PS other SDK calls do work likelogin so I know my app id etc are correct
-->
</script>
</html>
window.fbAsyninit=函数()
{
init({appId:'MYAPPID',status:true,cookie:true,xfbml:true});
};
(功能()
{
var e=document.createElement('script');
e、 异步=真;
e、 src=document.location.protocol+'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
分配给某人的职能
window.fbAsyninit将尽快运行
Facebook JS SDK已加载。任何
要在SDK运行后运行的代码
已加载的文件应放置在此文件中
函数,并在调用
FB.init()
现在试试这个
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function()
{
FB.init( {appId: 'MYAPPID', status: true, cookie: true, xfbml: true} );
alert( FB.Canvas.getPageInfo()["clientWidth"] );
};
(function()
{
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
window.fbAsyninit=函数()
{
init({appId:'MYAPPID',status:true,cookie:true,xfbml:true});
警报(FB.Canvas.getPageInfo()[“clientWidth”]);
};
(功能()
{
var e=document.createElement('script');
e、 异步=真;
e、 src=document.location.protocol+'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());