我正在运行一个加载远程数据的Flash应用,我们正在转换为使用(SSL)https://
我想知道是否可以像在JavaScript中一样使用“//”来自动采用父页面的协议(http或https)。
由于
更新:在我看来,你可以使用像“//www.something.com”这样的网址格式,但不是假设网页协议,它似乎只是默认为“{{ 3}}”。
现在我通过检查SWF是否是SSL网址来解决这个问题。像这样:
if( loaderInfo.url.indexOf("https:") == 0 ) {
//replace http: with https:
}
不幸的是,在处理远程资产URL的任何地方都不方便。只需加载匹配proto的所有东西就会更好......比如“//www.someurl.com/wouldbenicer.xml”,特别是因为js和html都是这样的。
布拉赫。
有什么想法吗?
答案 0 :(得分:1)
“//”相对proto在flash中不能像浏览器在HTML中使用url那样工作,而是默认为http://
解决方法:
检查SWF的URL以查看是否应修改要加载的URL以使其具有https:// protocol:
if( loaderInfo.url.indexOf("https:") == 0 ) {
//replace http: with https:
} else {
//replace https: with http:
}
答案 1 :(得分:1)
基于OG Sean的回答,这是一个包装函数,它将管理协议相对URL并默认为HTTP。
function relativeURL(url:String) {
var scheme = (loaderInfo.url.indexOf("https:") == 0) ? "https:": "http:";
var url = scheme + url.replace(/^https?:/,"");
return url;
}
答案 2 :(得分:0)
使用包含splash的字符串,并将其添加两次
var singlesplash:String = "/";
var doublesplash:String = singlesplash + singlesplash;
myurl = "http:" + doublesplash + "www.google.com";
或
myurl = "http:/" + "/www.google.com";