博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript中的位置协议属性
阅读量:2535 次
发布时间:2019-05-11

本文共 2320 字,大约阅读时间需要 7 分钟。

JavaScript | 位置协议属性 (JavaScript | Location protocol property)

A protocol by definition simply implies a set or working rules that must be adhered to. A network protocol thus defines rules for communication between network devices. You must be familiar with a lot of protocols already such as the infamous http (hypertext transfer protocol), the ftp (file transfer protocol) for transferring files between a client and a server on a computer network smtp, https, etc. In JS, the protocol is a property attached to the location object.

协议从定义上仅意味着必须遵守的一套或工作规则。 因此,网络协议定义了网络设备之间通信的规则。 您必须已经熟悉许多协议,例如臭名昭​​著的http (超文本传输​​协议), ftp (文件传输协议),用于在计算机网络上的客户端和服务器之间传输文件smtphttps等。在JS中,协议是附加到位置对象的属性。

Let's open a new chrome tab and see this in action,

让我们打开一个新的chrome标签并查看实际效果,

console.log(location);console.log(location.protocol);

Output

输出量

Location {href: "chrome-search://local-ntp/local-ntp.html", ancestorOrigins: DOMStringList, origin: "chrome-search://local-ntp", protocol: "chrome-search:", replace: ƒ, …}https:

The protocol property returns the protocol of the current URL. According to MDN docs, it is a DOMString containing the host, that is the hostname, a ':', and the port of the URL. On the homepage of google chrome, we get a different protocol because they use a different custom protocol for their search engines. Okay, let's see a simpler example. Go to any normal website, for example, includehelp.com and inside the dev console type in,

protocol属性返回当前URL的协议。 根据MDN文档,它是一个包含主机的DOMString,即主机名,“:”和URL的端口。 在谷歌浏览器的首页上,我们获得了不同的协议,因为他们为搜索引擎使用了不同的自定义协议。 好吧,让我们看一个简单的例子。 转到任何常规网站(例如includehelp.com),然后在开发控制台中输入以下内容:

location.protocol;

Output

输出量

"https:"

The URL follows an https: protocol hence returns us a string containing the name of that protocol (in this case, https) along with a colon. If you simply type in the location object you will see various other properties associated with it. However, you can easily notice that the location object gets you the properties of the current location that your URL indicates. If you navigate to different pages you'll see different values of these properties following the URL or the website you're visiting.

URL遵循https:协议,因此返回一个字符串,其中包含该协议的名称(在本例中为https)以及冒号。 如果您仅键入位置对象,您将看到与之关联的各种其他属性。 但是,您可以轻松地注意到location对象为您提供了URL指示的当前位置的属性。 如果导航到其他页面,则会在您访问的URL或网站之后看到这些属性的不同值。

翻译自:

转载地址:http://rnxzd.baihongyu.com/

你可能感兴趣的文章
hdu 1005 根据递推公式构造矩阵 ( 矩阵快速幂)
查看>>
安装php扩展
查看>>
百度移动搜索主要有如下几类结果构成
查看>>
Python爬虫面试题170道:2019版【1】
查看>>
JavaBean规范
查看>>
第四阶段 15_Linux tomcat安装与配置
查看>>
NAS 创建大文件
查看>>
学习笔记-模块之xml文件处理
查看>>
接口测试用例
查看>>
面试:用 Java 实现一个 Singleton 模式
查看>>
Sybase IQ导出文件的几种方式
查看>>
案例:手动输入一个字符串,打散放进一个列表,小写字母反序 大写字母保持不变...
查看>>
linux 系统下 tar 的压缩与解压缩命令
查看>>
阿里负载均衡,配置中间证书问题(在starcom申请免费DV ssl)
查看>>
转:How to force a wordbreaker to be used in Sharepoint Search
查看>>
MySQL存储过程定时任务
查看>>
Python中and(逻辑与)计算法则
查看>>
POJ 3267 The Cow Lexicon(动态规划)
查看>>
设计原理+设计模式
查看>>
音视频处理
查看>>