【发布时间】:2012-02-28 08:33:20
【问题描述】:
我上周启动了一个应用程序,并注意到在 Chrome 中只有我的画布的高度并不总是被调整。我花了很多时间研究这些问题,并注意到我有时会收到以下错误。
Unsafe JavaScript attempt to access frame with URL https://apps.facebook.com/tabletr/ from frame with URL
现在,对编程有所了解,我推断这可能是由于https 和http 可以互换使用。我(有时)在 Facebook 上“开启”安全浏览时遇到错误,而“关闭”时从来没有。
但我发现真正奇怪的是,通过 HTTPS 浏览时偶尔会出现此问题。我仍然没有找到任何模式来解决即将出现的问题或我的代码按预期工作。我知道这里有一些关于这个主题的帖子,我尝试了许多解决方法,但似乎没有一个解决我的问题。这是我的代码的一部分-
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<myid>', // App ID
channelUrl : '//tabletr.herokuapp.com/channel.php', // Channel File
status : false, // Check login status
cookie : true, // Enable cookies to allow the server to access the session
xfbml : false // Parse XFBML
});
// Additional initialization code here
FB.Canvas.setSize({ height: 1200 });
};
// If I comment out this function I don't get any unsafe URL errors
// anymore. I'm guessing that the include of the JavaScript code either
// fails to use the right protocol or is faulty in its implementation
// by Facebook. My money is on the former.
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
//js.src = "//connect.facebook.net/en_US/all.js";
js.src = "//tabletr.herokuapp.com/js/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
我该如何解决这个问题?老实说,我不在他们身边。也许我的频道文件实现有误?
更新代码
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<myid>', // App ID
channelUrl : '//tabletr.herokuapp.com/channel.php', // Channel File
status : false, // Check login status
cookie : true, // Enable cookies to allow the server to access the session
xfbml : false // Parse XFBML
});
// Additional initialization code here
FB.Canvas.setSize({ height: 1200 });
};
// If I comment out this function I don't get any unsafe URL errors
// anymore. I'm guessing that the include of the JavaScript code either
// fails to use the right protocol or is faulty in its implementation
// by Facebook. My money is on the former.
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
//js.src = "//tabletr.herokuapp.com/js/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
我已经根据 Stack Overflow 问题 Facebook JavaScript SDK over HTTPS loading non-secure items 更新了我的代码 - 但是,这还没有解决问题。我在 2012 年 1 月 19 日遇到了以下错误报告,它显示了我面临的相同症状。 Facebook 很快就会修复这个问题!
https://developers.facebook.com/bugs/192507854181725?browse=search_4f2bbd593f8798794293016
【问题讨论】:
标签: javascript xss frame unsafe facebook-javascript-sdk