2

我正在开发一个 Facebook 应用程序,它结合了我们的 Brightcove(视频主机)播放器及其 API。Facebook 为用户提供了安全浏览的选项,这带来了一些问题。就目前而言,我可以让应用程序在其中一种协议(http 或 https)上正常工作,但不能同时在这两种协议上正常工作。

https://www.facebook.com/atlantafalcons?sk=app_292392080815275(更改为 http:// 以查看它不起作用)

如果我将 BrightcoveExperiences.js 文件源设置为https://sadmin.brightcove.com/js/BrightcoveExperiences.js,那么当有人不安全浏览时它会引发错误。如果我将其设置为http://admin.brightcove.com/js/BrightcoveExperiences.js,那么当有人安全浏览时它会引发错误。

安全嵌入的文档在这里:http: //support.brightcove.com/en/docs/publishing-brightcove-player-https-page

有没有办法检测用户是否安全浏览以便能够选择加载哪个 JS 文件,或者有没有办法强制用户安全浏览?或者对于这样的问题是否有另一种解决方法?

提前致谢!

编辑: 能够想出一个解决方案(感谢 scibuff 建议检查谷歌分析):

<script type="text/javascript">
    var bJsHost = (("https:" == document.location.protocol ) ? "https://sadmin." : "http://admin.");
    document.write(unescape("%3Cscript src='" + bJsHost + "brightcove.com/js/BrightcoveExperiences.js' type='text/javascript'%3E%3C/script%3E"));
</script>
4

2 回答 2

2

使用相对于方案的 URI:

//admin.brightcove.com/js/BrightcoveExperiences.js

并且不要对 SSL 和非 SSL 实例使用不同的主机名。

(或者让 sadmin 响应非 SSL 请求的 301 重定向到 admin)

于 2012-03-02T16:56:35.950 回答
0

我会接受昆汀的建议。虽然,使用您的建议,您可以使用:

// window, top, self, document, others?
window.location.protocol

换句话说:

if (window.location.protocol == 'http:') {
    document.body.innerHTML = 'The page is using the http (non-secure) protocol.';
} else {
    document.body.innerHTML = 'The page is using the https (secure) protocol.';
}

http://jsfiddle.net/3NReg/

其他窗口/文档对象也可以工作,具体取决于您的需要:

// window, top, self, document, others?
if (self.location.protocol == 'http:') {
    document.body.innerHTML = 'The page is using the http (non-secure) protocol.';
} else {
    document.body.innerHTML = 'The page is using the https (secure) protocol.';
}

http://jsfiddle.net/3NReg/1/

于 2012-03-02T16:56:12.767 回答