2010-11-16 58 views

回答

10
window.location = window.location.href.replace(/^http:/, 'https:'); 
+5

好一个!你可能也想检查它是否为'http:'before:'if(window.location.protocol =='http:'){}' – pex 2010-11-16 03:17:38

2

如果你知道你的HTTP URL以 “http://”,那么很简单:

var httpsUrl = "https" + httpUrl.substring(4);