JavaScript location.protocolでhttpかhttpsの判定する方法

構文
location.protocol == 値
location.protocolを使用して通信プロトコルを判定します。
protocol は Location インターフェイスのプロパティで、 URL のプロトコルスキームを、最後の ':’ を含めて表す USVString です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
if (location.protocol == 'http:') {
console.log('http');
} else if (location.protocol == 'https:') {
console.log('https');
}
if (location.protocol == 'http:') { console.log('http'); } else if (location.protocol == 'https:') { console.log('https'); }
if (location.protocol == 'http:') {
      console.log('http');
} else if (location.protocol == 'https:') {
      console.log('https');
}

 

JavaScript

Posted by arkgame