File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,31 @@ const myURL =
6767 url .
parse (
' https://user:[email protected] :8080/p/a/t/h?query=string#hash' );
6868```
6969
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+
7095## The WHATWG URL API
7196
7297### Class: ` URL `
You can’t perform that action at this time.
0 commit comments