我正在开发一个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>
答案 0 :(得分:2)
使用方案相对URI:
//admin.brightcove.com/js/BrightcoveExperiences.js
不要为SSL和非SSL实例使用不同的主机名。
(或者让sadmin回复301重定向到非SSL请求的管理员)
答案 1 :(得分: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.';
}
其他窗口/文档对象也可能有效,具体取决于您的需求:
// 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.';
}