安全/不安全浏览问题



我正在开发一款Facebook应用程序,该应用程序集成了我们的Brightcove(视频主机)播放器及其API。脸书为用户提供了安全浏览的选择,这带来了一点问题。目前,我可以让应用程序在其中一种协议(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>

使用方案相关URI:

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

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

(或者让sadmin对非SSL请求进行301重定向以响应管理员)

我同意昆汀的建议。不过,根据您的建议,您可以使用:

// 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/

最新更新