This commit is contained in:
Ilya Kantor 2019-07-04 18:13:00 +03:00
parent b300836f00
commit b1b66a3065
9 changed files with 61 additions and 85 deletions

View file

@ -73,7 +73,7 @@ We can provide them in the URL string:
new URL('https://google.com/search?query=JavaScript')
```
...But that's not good due to encoding issues. Parameters need to be encoded if they contain spaces, non-latin letterrs, etc (more about that below).
...But parameters need to be encoded if they contain spaces, non-latin letters, etc (more about that below).
So there's URL property for that: `url.searchParams`, an object of type [URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams).
@ -96,7 +96,7 @@ url.searchParams.set('q', 'test me!'); // added parameter with a space and !
alert(url); // https://google.com/search?query=test+me%21
url.searchParams.set('tbs', 'qdr:y'); // add param for date range: past year
url.searchParams.set('tbs', 'qdr:y'); // this parameter specifies for date range for Google Search
alert(url); // https://google.com/search?q=test+me%21&tbs=qdr%3Ay