url对象
URL is a namespace used to host 2 static methods used to manipulate URLs using Blobs:
URL是一个命名空间,用于承载2个静态方法,这些静态方法用于使用Blob处理URL:
URL.createObjectURL()
URL.createObjectURL()
URL.revokeObjectURL()
URL.revokeObjectURL()
Given a blob, you generate a URL to it using the URL.createObjectURL()
function:
给定一个Blob,您可以使用URL.createObjectURL()
函数为其生成URL:
const myURL = URL.createObjectURL(aBlob)
Once you have the blob URL, you can destroy it from memory using:
拥有Blob URL后,可以使用以下方法从内存中销毁它:
URL.revokeObjectURL(myURL)
In addition to this, URL offers a very different functionality through its constructor, which can be used to create a URL. You can call it like this:
除此之外,URL通过其构造函数提供了非常不同的功能,可用于创建URL。 您可以这样称呼它:
const currentUrl = new URL(window.location.href)
Now currentUrl
has a set of properties you can use to inspect the URL:
现在, currentUrl
具有一组可用于检查URL的属性:
hash
the hash fragmenthash
列哈希片段host
the domain + porthost
域+端口hostname
the domainhostname
域href
contains the entire URLhref
包含整个URLorigin
scheme + domain + portorigin
方案+域+端口password
password
pathname
pathname
port
port
protocol
protocol
search
search
searchParams
searchParams
username
username
which are the usual parts of a URL.
这是网址的常见部分。
You can alter any of those, except origin
and searchParams
which are read only, and generate a new URL string by calling the toString()
method, or by referencing the href
property.
您可以更改所有这些内容(只读的origin
和searchParams
除外),并通过调用toString()
方法或引用href
属性来生成新的URL字符串。
url对象