A lightweight JavaScript library to manipulate the page url.
Browse the demos on http://jillix.github.io/url.js/
The library is available on CDNJS as well. To use it, just do:
<script src="https://cdnjs.cloudflare.com/ajax/libs/urljs/2.6.2/url.min.js"></script>
<script src="path/to/url.js"></script>
<!-- or use the cdn
<script src="https://cdnjs.cloudflare.com/ajax/libs/urljs/2.6.2/url.min.js"></script>
-->
<script>
Url.updateSearchParam("answer", 42);
</script>
The library is CommonJS-compatible. You can require("url.js")
in your files.
Check out the dist
directory to download the needed files and include them on your page.
If you're using this module in a CommonJS environment, you can install it using npm
or yarn
and require
it:
# Using npm
npm install --save urljs
# Using yarn
yarn add urljs
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. π
Finds the value of parameter passed in first argument.
- String
name
: The parameter name. - Boolean
notDecoded
: Iftrue
, the result will be encoded.
- String|Boolean|Undefined The parameter value (as string),
true
if the parameter is there, but doesn't have a value, orundefined
if it is missing.
Parses a string as querystring. Like the queryString
method does, if
the parameter is there, but it doesn't have a value, the value will
be true
.
- String
search
: An optional string that should be parsed (default:window.location.search
).
- Object The parsed querystring. Note this will contain empty strings for
Stringifies a query object.
- Object
queryObj
: The object that should be stringified.
- String The stringified value of
queryObj
object.
Adds, updates or deletes a parameter (without page refresh).
- String|Object
param
: The parameter name or name-value pairs as object. - String
value
: The parameter value. Ifundefined
, the parameter will be removed. - Boolean
push
: Iftrue
, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location. - Boolean
triggerPopState
: Triggers the popstate handlers (by default falsly).
- Url The
Url
object.
Returns the page url, but not including the domain name.
- Boolean
excludeHash
: Iftrue
, the location hash will not be appended in the result.
- String The page url (without domain).
Sets/gets the hash value.
- String
newHash
: The hash to set. - Boolean
triggerPopState
: Triggers the hashchange (by default falsly).
- String The location hash.
Update the full url (pathname, search, hash).
- String
s
: The new url to set. - Boolean
push
: Iftrue
, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location. - Boolean
triggerPopState
: Triggers the popstate handlers (by default falsly).
- String The set url.
Sets/gets the pathname.
- String
pathname
: The pathname to set. - Boolean
push
: Iftrue
, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location. - Boolean
triggerPopState
: Triggers the popstate handlers (by default falsly).
- String The set url.
Calls the hashchange handlers.
Calls the popstate handlers.
Adds a popstate handler.
- Function
cb
: The callback function.
Adds a hashchange handler.
- Function
cb
: The callback function.
Removes the hash from the url.
- Boolean
push
: Iftrue
, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location. - Boolean
trigger
: Triggers the popstate handlers (by default falsly).
Removes the querystring parameters from the url.
- Boolean
push
: Iftrue
, the page will be kept in the history, otherwise the location will be changed but by pressing the back button will not bring you to the old location. - Boolean
trigger
: Triggers the popstate handlers (by default falsly).
Have an idea? Found a bug? See how to contribute.
If you are using this library in one of your projects, add it in this list. β¨
ember-cli-mocha-reporter