File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,31 @@ const myURL =
67
67
url .
parse (
' https://user:[email protected] :8080/p/a/t/h?query=string#hash' );
68
68
```
69
69
70
+ ### Constructing a URL from component parts and getting the constructed string
71
+
72
+ It is possible to construct a WHATWG URL from component parts using either the
73
+ property setters or a template literal string:
74
+
75
+ ``` js
76
+ const myURL = new URL (' https://example.org' );
77
+ myURL .pathname = ' /a/b/c' ;
78
+ myURL .search = ' ?d=e' ;
79
+ myURL .hash = ' #fgh' ;
80
+ ```
81
+
82
+ ``` js
83
+ const pathname = ' /a/b/c' ;
84
+ const search = ' ?d=e' ;
85
+ const hash = ' #fgh' ;
86
+ const myURL = new URL (` https://example.org${ pathname}${ search}${ hash} ` );
87
+ ```
88
+
89
+ To get the constructed URL string, use the ` href ` property accessor:
90
+
91
+ ``` js
92
+ console .log (myURL .href );
93
+ ```
94
+
70
95
## The WHATWG URL API
71
96
72
97
### Class: ` URL `
You can’t perform that action at this time.
0 commit comments