Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLSearchParam.append Encoding Behavior #37676

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions files/en-us/web/api/urlsearchparams/append/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface appends a specified key/value pair as a new search parameter.
As shown in the example below, if the same key is appended multiple times it will
appear in the parameter string multiple times for each value.

As shown in the second example below, both `name` and `value` will be automatically
encoded to be URL safe.

## Syntax

```js-nolint
Expand All @@ -34,6 +37,8 @@ None ({{jsxref("undefined")}}).
## Examples

```js
//Example: Adding the same param multiple times

let url = new URL("https://example.com?foo=1&bar=2");
let params = new URLSearchParams(url.search);

Expand All @@ -42,6 +47,16 @@ params.append("foo", 4);
//Query string is now: 'foo=1&bar=2&foo=4'
```

```js
//Example: Demostrating the encoding behavior

const params = new URLSearchParams();

params.append("needsEncoding$%&$#@++++++", "needsEncoding$#&*@#()+++++");
params.toString();
//"needsEncoding%24%25%26%24%23%40%2B%2B%2B%2B%2B%2B=needsEncoding%24%23%26*%40%23%28%29%2B%2B%2B%2B%2B"
```

## Specifications

{{Specifications}}
Expand Down
Loading