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.
If :
alert(typeof(document.height));
alerts "number";
Your code should work fine.
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:
- Your access of the
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?
精彩评论