• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    CSS
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📃 A lightweight JavaScript library to manipulate the page url.

url.js

Version Downloads

A lightweight JavaScript library to manipulate the page url.

Demo

Browse the demos on http://jillix.github.io/url.js/

CDN

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>

Usage

<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>

CommonJS-compatible

The library is CommonJS-compatible. You can require("url.js") in your files.

☁️ Installation

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

Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. 🐛

📝 Documentation

queryString(name, notDecoded)

Finds the value of parameter passed in first argument.

Params

  • String name: The parameter name.
  • Boolean notDecoded: If true, the result will be encoded.

Return

  • String|Boolean|Undefined The parameter value (as string), true if the parameter is there, but doesn't have a value, or undefined if it is missing.

parseQuery(search)

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.

Params

  • String search: An optional string that should be parsed (default: window.location.search).

Return

  • Object The parsed querystring. Note this will contain empty strings for

stringify(queryObj)

Stringifies a query object.

Params

  • Object queryObj: The object that should be stringified.

Return

  • String The stringified value of queryObj object.

updateSearchParam(param, value, push, triggerPopState)

Adds, updates or deletes a parameter (without page refresh).

Params

  • String|Object param: The parameter name or name-value pairs as object.
  • String value: The parameter value. If undefined, the parameter will be removed.
  • Boolean push: If true, 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).

Return

  • Url The Url object.

getLocation(excludeHash)

Returns the page url, but not including the domain name.

Params

  • Boolean excludeHash: If true, the location hash will not be appended in the result.

Return

  • String The page url (without domain).

hash(newHash, triggerPopState)

Sets/gets the hash value.

Params

  • String newHash: The hash to set.
  • Boolean triggerPopState: Triggers the hashchange (by default falsly).

Return

  • String The location hash.

_updateAll(s, push, triggerPopState)

Update the full url (pathname, search, hash).

Params

  • String s: The new url to set.
  • Boolean push: If true, 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).

Return

  • String The set url.

pathname(pathname, push, triggerPopState)

Sets/gets the pathname.

Params

  • String pathname: The pathname to set.
  • Boolean push: If true, 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).

Return

  • String The set url.

triggerHashchangeCb()

Calls the hashchange handlers.

triggerPopStateCb()

Calls the popstate handlers.

onPopState(cb)

Adds a popstate handler.

Params

  • Function cb: The callback function.

onHashchange(cb)

Adds a hashchange handler.

Params

  • Function cb: The callback function.

removeHash(push, trigger)

Removes the hash from the url.

Params

  • Boolean push: If true, 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).

removeQuery(push, trigger)

Removes the querystring parameters from the url.

Params

  • Boolean push: If true, 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).

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

💫 Where is this library used?

If you are using this library in one of your projects, add it in this list.

  • ember-cli-mocha-reporter

📜 License

MIT © jillix

More Repositories

1

jQuery-sidebar

🍫 A stupid simple sidebar jQuery plugin.
JavaScript
216
star
2

svg.connectable.js

🔀 A JavaScript library for connecting SVG things.
CSS
105
star
3

svg.pan-zoom.js

🐭 A JavaScript library for panning and zooming SVG things.
CSS
75
star
4

medium-editor-custom-html

❎ An extension that inserts custom HTML using a new button in the Medium Editor toolbar
HTML
74
star
5

svg.draggy.js

🐭 A JavaScript library for dragging SVG things.
CSS
65
star
6

piklor.js

🎨 A tiny JavaScript color picker library.
CSS
62
star
7

jQuery-json-editor

🇮🇹 A jQuery plugin for editing JSON data.
HTML
29
star
8

jQuery-form-serializer

🅰️ Serialize forms to JSON objects in a friendly way.
CSS
18
star
9

jQuery-prompt21

🅰️ A minimalist jQuery prompt plugin for the 21st Century.
CSS
14
star
10

csv-to-array

✌️ A small NPM library for converting CSV files to JSON arrays.
JavaScript
11
star
11

a-csv

🎃 A lightweight CSV parser.
JavaScript
6
star
12

worky

👷 An EventEmitter like interface for web workers.
CSS
5
star
13

jQuery-image-upload

👴 A jQuery plugin that adds controls to the selected jQuery elements with a simple call.
JavaScript
4
star
14

kubernetes-mysql-prestashop-pd

Shell
3
star
15

engine-terminal

🚒 The web term version for Engine.
JavaScript
2
star
16

schema

JSON-LD Schemas for structured data
JavaScript
2
star
17

materializecss-theme

🎨 A jillix theme based on the materializecss framework.
CSS
2
star
18

cayley-jsonld-io

JSON-LD based cayley driver
JavaScript
2
star
19

svg.cytoscape.js

♻️ Build cytoscape environments in SVG.
JavaScript
2
star
20

flow-browser

Flow for client side environments
JavaScript
2
star
21

modm

💼 Mongodb Object Document Mapper
JavaScript
2
star
22

ruut.js

🐏 A tiny and fast route parsing library, supporting parameters and more.
JavaScript
2
star
23

flow-api

🔆 Flow API
JavaScript
2
star
24

wrabbit

💃 Wrap scripts by providing the wrapping function.
JavaScript
1
star
25

captcha

🎓 Mono module for captcha
JavaScript
1
star
26

starter

⭐ A basic starter project
HTML
1
star
27

jQuery-image-resize

🎃 Lightweight jQuery plugin that adds resize controls to selected images.
JavaScript
1
star
28

libobject

Object utility library
JavaScript
1
star
29

engine-builder

👷 Composition parser for engine
JavaScript
1
star
30

enny

📎 Generate Engine compositions from human-readable inputs.
JavaScript
1
star