facebook JavaScript json
我想将 document.height 分配给变量 H
,我该如何完成此操作?
var H = document.height;
var p = { width: 520, height: H };
FB.Canvas.setSize(p);
我将如何在 JavaScript 中做到这一点? height: H
的表达是否正确?它不起作用。
I would like to assign document.height to the variable H
, how can I accomplish this?
var H = document.height;
var p = { width: 520, height: H };
FB.Canvas.setSize(p);
How would I do this in javascript? Was it correct expression height: H
? It didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果:
警报“数字”;
你的代码应该可以正常工作。
If :
alerts "number";
Your code should work fine.
我从未为 Facebook 编写过任何 JavaScript,因此以下是一个有根据的猜测。
出于安全原因,Facebook 可能会在
iframe
沙箱中运行您的 JavaScript。简单看一下 Google 结果似乎也表明他们进行了预处理在运行代码之前,通过消除安全问题、访问被禁止的 DOM API 等来“清理”它。考虑到这个合理的假设,您的代码无法正常工作的两个原因浮现在脑海中:
document
的访问 对象出于安全原因被禁止,因此从您的清理脚本中删除或以某种方式禁用。document
指的是HTMLDocument
在运行 JavaScript 的iframe
中呈现,在这种情况下,height
将是此iframe
的高度,而不是整个 Facebook 页面的高度你可能正在期待。Facebook 开发者工具有帮助吗?您的控制台中是否记录了任何错误?
I've never written any JavaScript for Facebook, so what follows is an educated guess.
Facebook are probably running your JavaScript within an
iframe
sandbox for security reasons. A brief look at Google results also seems to suggest that they pre-process your code before running it, to "sanitize" it by removing security issues, access to banned DOM APIs etc.Given this reasonable assumption, two reasons why your code is not working come to mind:
document
object is banned for security reasons, so removed from your sanitized script or disabled in some way.document
refers to theHTMLDocument
rendered in theiframe
within which your JavaScript is running, in which caseheight
will be the height of thisiframe
, not the entire Facebook page as you are probably expecting.Do any Facebook developer tools help here? Are there any errors logged in your console?