在评论后面的答案时,nute和James Westgate是正确的。
如果我们看一下杂乱无章的工业级外部javascript包含,成功的javascript使用document.location.protocol嗅探和脚本元素注入都使用正确的协议。
所以你可以使用类似:
var protocol = (
("https:" == document.location.protocol)
? "https"
: "http"
);
document.write(
unescape(
"%3Cscript"
+ " src='"
+ protocol
+ "://"
+ "your.domain.tld"
+ "/your/script.js"
+ "'"
+ " type='text/javascript'
+ "%3E"
+ "%3C/script%3E"
) // this HAS to be escaped, otherwise it would
// close the actual (not injected)
);
外部CSS包含也可以这样做。
顺便说一句:注意在CSS中仅使用相对url()路径(如果有的话),否则您可能仍会收到“混合的安全和不安全”警告。