URL相关Web APIs
参考文档:MDN> Web API接口 > URLUtils
MDN > Web API接口 > HTMLAnchorElement
一、URLUtils
1. 定义了和URL相关的一些实用方法
2. URLUtils本身没有对象,但是有几个类型实现了它:Location,URL,HTMLAnchorElement,HTMLAreaElement
3. 属性
|
属性 |
描述 |
举例 |
|
包含整个URL的一个DOMString |
https://developer.mozilla.org/en-US/search?q=URL#search-results-close-container |
|
|
包含URL对应协议的一个DOMString,最后有一个":"。 |
https: |
|
|
包含了域名的一个DOMString,可能在该串最后带有一个":"并跟上URL的端口号。(若端口号为该scheme的默认端口号,则省略) |
developer.mozilla.org 若href="https://developer.mozilla.org:443/",host也为developer.mozilla.org 若href="https://developer.mozilla.org:4097/",host为developer.mozilla.org:4097 若href="http://www.126.com/",host为www.126.com 若href="http://www.126.com:80/",host也为www.126.com |
|
|
包含URL域名的一个DOMString。 |
developer.mozilla.org |
|
|
包含端口号的一个DOMString。 (若端口号为该scheme的默认端口号,则结果为空字符串) |
"" 若href="https://developer.mozilla.org:443/",port也为"" 若href="https://developer.mozilla.org:4097/",port为"4097" 若href="http://www.126.com/",port也为"" 若href="http://www.126.com:80/",port也为"" |
|
|
包含URL中路径部分的一个DOMString,开头有一个"/"。 |
/en-US/search |
|
|
包含URL参数的一个DOMString,开头有一个"?"。 |
?q=URL |
|
|
包含块标识符的DOMString,开头有一个"#"。 |
#search-results-close-container |
|
|
包含URL中域名前的用户名的一个DOMString。 |
||
|
包含URL域名前的密码的一个 DOMString。 |
||
|
包含页面来源的域名的标准形式DOMString。 |
||
|
Returns a URLSearchParams object allowing to access the GET query arguments contained in the URL. |
4. 方法
|
方法 |
描述 |
举例 |
|
返回一个DOMString,包含整个URL。 它和读取URLUtils.href的效果相同。但是用它是不能够修改Location的值的。 |
||
二、URL
1. URL 接口是一个包含若干静态方法的对象,用来创建 URLs。
2. 属性
3. 方法
4. 构造器
- URL() 构造函数返回一个新创建的URL对象,表示由参数定义的URL。
- 语法
url = new URL(urlString, [baseURLstring])
url = new URL(urlString, baseURLobject)
|
参数 |
描述 |
|
urlString |
是一个表示绝对或相对URL的DOMString。 如果urlString是相对URL,则baseURLstring或baseURLobject(无论存在)都将用作基本URL。 如果urlString是绝对URL,则将忽略baseURLstring和baseURLobject。 |
|
baseURLstring |
是一个表示基本URL的DOMString,以便在urlString是相对URL时使用。 如果未指定,且在参数中未传递baseURLobject,则默认为"about:blank"。 如果它是一个无效的绝对URL,构造函数将引发一个类型为SYNTAX_ERROR的DOMException |
|
baseURLobject |
是表示基本URL的URL 对象,以便在urlString是相对URL时使用。 |
- 例:
var a = new URL("/", "https://developer.mozilla.org"); // Creates a URL pointing to 'https://developer.mozilla.org/'
var b = new URL("https://developer.mozilla.org"); // Creates a URL pointing to 'https://developer.mozilla.org'
var c = new URL('en-US/docs', b); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var d = new URL('/en-US/docs', b); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var f = new URL('/en-US/docs', d); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var g = new URL('/en-US/docs', "https://developer.mozilla.org/fr-FR/toto");// Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var h = new URL('/en-US/docs', a); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var i = new URL('/en-US/docs', ''); // Raises a SYNTAX ERROR exception as '/en-US/docs' is not valid
var j = new URL('/en-US/docs'); // Raises a SYNTAX ERROR exception as 'about:blank/en-US/docs' is not valid
var k = new URL('http://www.example.com', 'https://developers.mozilla.com');// Creates a URL pointing to 'https://www.example.com'
var l = new URL('http://www.example.com', b); // Creates a URL pointing to 'https://www.example.com'
5. 静态方法
|
方法 |
描述 |
|
返回一个DOMString ,包含一个唯一的blob链接(该链接协议为以blob:,后跟唯一标识浏览器中的对象的掩码)。 |
|
|
销毁之前使用URL.createObjectURL()方法创建的URL实例。 |
三、Location
1. Location表示其关联的对象所展示的页面的地址等信息,对该对象的修改会反映到关联的对象上。 Document 和 Window 接口都有一个关联的Location,可以分别用Document.location和Window.location来访问它们对应的Location。
2. 属性
实现URLUtils的属性(除URLUtils.searchParams以外)
3. 方法
- 实现URLUtils的方法
- Location本身的方法
|
方法 |
描述 |
|
加载给定URL的内容资源到这个Location对象所关联的对象上。 |
|
|
重新加载来自当前 URL的资源。他有一个特殊的可选参数,类型为 Boolean,该参数为true时会导致该方法引发的刷新一定会从服务器上加载数据。如果是 false或没有制定这个参数,浏览器可能从缓存当中加载页面。 |
|
|
用给定的URL替换掉当前的资源。与 assign() 方法不同的是用 replace()替换的新页面不会被保存在会话的历史 History中,这意味着用户将不能用后退按钮转到该页面。 |
四、HTMLAnchorElement
1. HTMLAnchorElement 接口表示超链接元素,并提供一些特别的属性和方法以用于操作这些元素的布局和显示。
2. 属性
- 继承自父类HTMLElement的属性
|
是一个代表了单个字符的 DOMString,单个字符可以切换输入焦点到超链接。 |
|
|
Is a DOMString representing the character encoding of the linked resource. |
|
|
Is a DOMString representing a comma-separated list of coordinates. |
|
|
Is a DOMString indicating that the linked resource is intended to be downloaded rather than displayed in the browser. The value represent the proposed name of the file. If the name is not a valid filename of the underlying OS, browser will adapt it. The value is a URL with a scheme like http:, file:, data: or even blob: (created with URL.createObjectURL). |
|
|
Is a DOMString that reflects the hreflang HTML attribute, indicating the language of the linked resource. |
|
|
Is a DOMString that reflects the media HTML attribute, indicating the intended media for the linked resource. |
|
|
Is a DOMString representing the anchor name. |
|
|
Is a DOMString that reflects the rel HTML attribute, specifying the relationship of the target object to the linked object. |
|
|
Returns a DOMTokenList that reflects the rel HTML attribute, as a list of tokens. |
|
|
Is a DOMString representing that the rev HTML attribute, specifying the relationship of the link object to the target object. |
|
|
Is a DOMString representing the shape of the active area. |
|
|
Is a long containing the position of the element in the tabbing navigation order for the current document. |
|
|
Is a DOMString that reflects the target HTML attribute, indicating where to display the linked resource. |
|
|
Is a DOMString being a synonym for the Node.textContent property. |
|
|
Is a DOMString that reflects the type HTML attribute, indicating the MIME type of the linked resource. |
- 实现URLUtils的属性(除URLUtils.searchParams以外)
3. 方法
- 继承自父类HTMLElement的方法
|
方法 |
描述 |
|
Removes the keyboard focus from the current element. |
|
|
Gives the keyboard focus to the current element. |
|
|
用给定的URL替换掉当前的资源。与 assign() 方法不同的是用 replace()替换的新页面不会被保存在会话的历史 History中,这意味着用户将不能用后退按钮转到该页面。 |
- 实现URLUtils的方法
URL相关Web APIs的更多相关文章
- 《RESTful Web APIs中文版》
<RESTful Web APIs中文版> 基本信息 原书名:RESTful Web APIs 原出版社: O'Reilly Media 作者: Leonard Richardson ...
- 前端Web APIs 二
day04 - Web APIs 学习目标: 能够说出常用的3-5个键盘事件 能够知道如何获取当前键盘按下的是哪个键 能够知道浏览器的顶级对象window 能够使用window.onload事件 能够 ...
- 前端Web APIS
day01 - Web APIs 学习目标: 能够通过ID来获取元素能够通过标签名来获取元素能够通过class来获取元素能够通过选择器来获取元素能够获取body和html元素能够给元素注册事件能够修改 ...
- Web APIs 基于令牌TOKEN验证的实现
Web APIs 基于令牌TOKEN验证的实现 概述: ASP.NET Web API 的好用使用过的都知道,没有复杂的配置文件,一个简单的ApiController加上需要的Action就能工作.但 ...
- ASP.NET Web APIs 基于令牌TOKEN验证的实现(保存到DB的Token)
http://www.cnblogs.com/niuww/p/5639637.html 保存到DB的Token 基于.Net Framework 4.0 Web API开发(4):ASP.NET We ...
- JS - url相关
今天在找获取当前网址除去参数的js方式,结果自己会的竟然只有window.location.href 查到的一篇博文: http://www.cnblogs.com/weiyuxinghuacun/a ...
- URL相关的工具类
package com.opslab.util.web; import com.opslab.util.CharUtil;import com.opslab.util.CharsetUtil;impo ...
- ECMAScript Web APIs node.js
https://hacks.mozilla.org/2015/04/es6-in-depth-an-introduction/ What falls under the scope of ECMASc ...
- Claim-based-security for ASP.NET Web APIs using DotNetOpenAuth
Recently I worked with a customer assisting them in implementing their Web APIs using the new ASP.NE ...
随机推荐
- PHP实现多继承 trait 语法
原文地址:http://small.aiweimeng.top/index.php/archives/50.html PHP没有多继承的特性.即使是一门支持多继承的编程语言,我们也很少会使用这个特性. ...
- Linux学习-计算机基础
Linux 学习-计算机基础 一.描述计算机的组成及其功能. 计算机系统是由硬件(Hardware)和软件(Software )两部分组成. 硬件: 从硬件基本结构上来讲,计算机是由运算器.控制器.存 ...
- 项目开发设计模式理解之MVC模式
项目开发设计模式之MVC模式: M model 模型层 V view 视图层 C control 控制器 MVC模式在B/S架构下使用很广泛的软件设计模式,分成三个相对独立的模块构成,model+vi ...
- 20155204 2016-2017-2 《Java程序设计》第2周学习总结
20155204 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 本章主要学习了Java语言的基础语法,基本同C语言逻辑相通,比较着学不算难理解,包括了一些简 ...
- 20155336 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20155336 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Jav ...
- 20155339 2016-2017-2 《Java程序设计》第4周学习总结
20155339 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 继承.多态与is-a 继承就是避免多个类间重复定义共同行为. 可以把相同的成粗代码提升为父类 ...
- 【Windows10】我的电脑从新装到优化配置
[Windows10]我的电脑从新装到优化配置 必装软件 Visual Studio Microsoft VS Code Microsoft Expression Design 4 Notepad2- ...
- [BZOJ1492][NOI2007]cash-[cdq分治]
Description 传送门 Solution 首先,最优情况一定是某一天把所有金券卖出或买入是最优的. 在金券一定的情况下,分散卖一定没有统一在最优的那天卖更优. 然后,我们假定在某一天卖,则在该 ...
- OpenCV人脸识别的原理 .
OpenCV人脸识别的原理 . 在之前讲到的人脸测试后,提取出人脸来,并且保存下来,以供训练或识别是用,提取人脸的代码如下: void GetImageRect(IplImage* orgImage, ...
- [CF888E] Maximum Subsequence 序列分治
早期作品,不喜轻喷. LG传送门 序列分治板子题. 切这道题用了好长时间,所以想发篇题解作为纪念 . 首先,我们认真观察题目数据(面向数据做题是个好习惯),发现题目的\(n\)竟然只有\(35\),我 ...