protocol屬性設(shè)置或返回當(dāng)前URL的協(xié)議,包括冒號(hào)(:)。
返回協(xié)議屬性:
location.protocol
設(shè)置協(xié)議屬性:
location.protocol = protocol
var x = location.protocol; document.querySelector("#output").innerHTML = x;測(cè)試看看?/?
所有瀏覽器都完全支持protocol屬性:
屬性 | ![]() | ![]() | ![]() | ![]() | ![]() |
protocol | 是 | 是 | 是 | 是 | 是 |
值 | 描述 |
---|---|
protocol | 字符串,指定URL的協(xié)議 可能的值:
|
返回值: | 一個(gè)字符串,表示當(dāng)前URL的協(xié)議,包括冒號(hào)(:) |
---|
此示例顯示所有位置屬性:
var txt = ""; txt += "<p>Host: " + location.host + "</p>"; txt += "<p>Hostname: " + location.hostname + "</p>"; txt += "<p>Href: " + location.href + "</p>"; txt += "<p>Origin: " + location.origin + "</p>"; txt += "<p>Pathname: " + location.pathname + "</p>"; txt += "<p>Protocol: " + location.protocol + "</p>"; txt += "<p>Search: " + location.search + "</p>"; document.write(txt);測(cè)試看看?/?
位置參考:location.href屬性
位置參考:location.host屬性
位置參考:location.origin屬性