开发者

facebook javascript json

开发者 https://www.devze.com 2023-02-28 22:12 出处:网络
I would like to assign document.开发者_如何学编程height to the variable H, how can I accomplish this?

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:

  1. Your access of the document object is banned for security reasons, so removed from your sanitized script or disabled in some way.
  2. document refers to the HTMLDocument rendered in the iframe within which your JavaScript is running, in which case height will be the height of this iframe, 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消