---
title: URLUtils
slug: Web/API/URLUtils
translation_of: Web/API/HTMLHyperlinkElementUtils
---
{{ApiRef("URL API")}}{{SeeCompatTable}}
The HTMLHyperlinkElementUtils
mixin defines utility methods and properties to work with {{domxref("HTMLAnchorElement")}} and {{domxref("HTMLAreaElement")}}. These utilities allow to deal with common features like URLs.
There are no objects of this type, but several objects {{domxref("HTMLAnchorElement")}} and {{domxref("HTMLAreaElement")}} implement it.
属性
注意:This interface doesn't inherit any property.
- {{domxref("HTMLHyperlinkElementUtils.href")}}
- This is a {{domxref("USVString")}} containing the whole URL.
- {{domxref("HTMLHyperlinkElementUtils.protocol")}}
- This is a {{domxref("USVString")}} containing the protocol scheme of the URL, including the final
':'
.
- {{domxref("HTMLHyperlinkElementUtils.host")}}
- This is a {{domxref("USVString")}} containing the host, that is the hostname, and then, if the port of the URL is not empty (which can happen because it was not specified or because it was specified to be the default port of the URL's scheme), a
':'
, and the port of the URL.
- {{domxref("HTMLHyperlinkElementUtils.hostname")}}
- This is a {{domxref("USVString")}} containing the domain of the URL.
- {{domxref("HTMLHyperlinkElementUtils.port")}}
- This is a {{domxref("USVString")}} containing the port number of the URL.
- {{domxref("HTMLHyperlinkElementUtils.pathname")}}
- This is a {{domxref("USVString")}} containing an initial
'/'
followed by the path of the URL.
- {{domxref("HTMLHyperlinkElementUtils.search")}}
- This is a {{domxref("USVString")}} containing a
'?'
followed by the parameters of the URL.
- {{domxref("HTMLHyperlinkElementUtils.hash")}}
- This is a {{domxref("USVString")}} containing a
'#'
followed by the fragment identifier of the URL.
- {{domxref("HTMLHyperlinkElementUtils.username")}}
- This is a {{domxref("USVString")}} containing the username specified before the domain name.
- {{domxref("HTMLHyperlinkElementUtils.password")}}
- This is a {{domxref("USVString")}} containing the password specified before the domain name.
- {{domxref("HTMLHyperlinkElementUtils.origin")}} {{readonlyInline}}
- This returns a {{domxref("USVString")}} containing the origin of the URL (that is its scheme, its domain and its port).
方法
注意:This interface doesn't inherit any method.
- {{domxref("HTMLHyperlinkElementUtils.toString()")}}
- This returns a {{domxref("USVString")}} containing the whole URL. It is a synonym for {{domxref("HTMLHyperlinkElementUtils.href")}}, though it can't be used to modify the value.
规范
规范 |
状态 |
备注 |
{{SpecName('HTML WHATWG', '#htmlhyperlinkelementutils', 'HTMLHyperlinkElementUtils')}} |
{{Spec2('HTML WHATWG')}} |
Initial definition |
浏览器兼容性
{{Compat("api.HTMLHyperlinkElementUtils")}}
参见
- Interfaces implementing this one: {{domxref("HTMLAnchorElement")}}, {{domxref("HTMLAreaElement")}}