UNPKG

1.34 kBMarkdownView Raw
1url-search-params
2=================
3
4[![build status](https://secure.travis-ci.org/WebReflection/url-search-params.svg)](http://travis-ci.org/WebReflection/url-search-params)
5
6This is a polyfill for the [URLSearchParams API](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).
7
8It is possible to simply include [build/url-search-params.js](build/url-search-params.js) or grab it via npm.
9
10```
11npm install url-search-params
12```
13
14The function is exported directly.
15```js
16var URLSearchParams = require('url-search-params');
17```
18
19MIT Style License
20
21#### About HTMLAnchorElement.prototype.searchParams
22This property is already implemented in Firefox and polyfilled here only for browsers that exposes getters and setters
23through the `HTMLAnchorElement.prototype`.
24
25In order to know if such property is supported, you **must** do the check as such:
26```
27if ('searchParams' in HTMLAnchorElement.prototype) {
28 // polyfill for <a> links supported
29}
30```
31If you do this check instead:
32```js
33if (HTMLAnchorElement.prototype.searchParams) {
34 // throws a TypeError
35}
36```
37this polyfill will reflect native behavior, throwing a type error due access to a property in a non instance of `HTMLAnchorElement`.
38
39Nothing new to learn here, [just a reminder](http://webreflection.blogspot.co.uk/2011/08/please-stop-reassigning-for-no-reason.html).