2013-05-08 28 views
2

我的代碼指定如何指定依賴於當前URL的HTTP或HTTPS?

this._restUrl = "http://" + this._info.host + "/app/rest/"; 

問題是我無法弄清楚如何使它使用「https://開頭」當使用SSL。我怎樣才能把它變成一個http或https語句?這工作正常,因爲它是http。

+0

你也可以做'window.location.protocol + 「//」 + this._info ...' – Blender 2013-05-08 01:46:13

回答

3

您可以使用相對協議:

this._restUrl = "//" + this._info.host + "/app/rest/"; 

Here’s a good description of those.

+0

我只是搜查,在您的帖子後找到該頁面。非常感謝你!我無法找到我正在尋找的名字。這太簡單了! – moonman407 2013-05-08 01:45:24

相關問題