English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Location protocol 属性

JavaScript Location  Objekt

protocol属性设置或返回当前URL的协议,包括冒号(:)。

语法:

返回协议属性:

location.protocol

设置协议属性:

location.protocol = protocol
var x = location.protocol;
document.querySelector("#output").innerHTML = x;
Testen Sie heraus‹/›

浏览器兼容性

所有浏览器都完全支持protocol属性:

属性
protocol

属性值

描述
protocol字符串,指定URL的协议
可能的值:
  • http:

  • https:

  • file:

  • FTP:

  • mailto:

  • 更多...

技术细节

返回值:一个字符串,表示当前URL的协议,包括冒号(:)

更多示例

Dieser Beispiel zeigt alle Positionseigenschaften:

var txt = "";
txt += "<p>Host: " + location.host + "</p>";
txt += "<p>Hostname: " + location.hostname + "</p>";
txt += "<p>Href: " + location.href + "</p>";
txt += "<p>Ursprung: " + location.origin + "</p>";
txt += "<p>Pfadname: " + location.pathname + "</p>";
txt += "<p>Protokoll: " + location.protocol + "</p>";
txt += "<p>Search: " + location.search + "</p>";
document.write(txt);
Testen Sie heraus‹/›

Verwandte Referenzen

Position Referenz:location.href-Eigenschaft

Position Referenz:location.host-Eigenschaft

Position Referenz:location.origin-Eigenschaft

JavaScript Location  Objekt