2010-11-16 56 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);