set-location-hash.js
A client-side library to set the anchor portion of current URL without scrolling
// On http://yoursite.com/ ;locationhref; //=> "http://yoursite.com/#foo"
Installation
Package managers
Bower
bower i --save set-location-hash
npm
npm i --save set-location-hash
Duo
var setLocationHash = ;
Standalone
Download the script file directly.
AMD support
This repository includes the AMD-friendly build but the package managers doesn't include it. If you want to use it, download it directly.
API
setLocationHash(identifier [, options])
identifier: String
options: Object
Return: String
(Current entire URL)
Change the fragment identifier of current URL to the String
of the identifier
argument.
This function is vary similar to location.hash
property, but this function won't change the scroll position of the page unlike location.hash
.
If the browser supports history.pushState
and history.replaceState
, you can set replace
and force
options by passing an Object
to the options
argument.
options.replace
Type: Boolean
Default: false
Replace the browser history instead of pushing a new history.
// On http://yoursite.com/ historylength; //=> 1 ;historylength; //=> 1 ;historylength; //=> 2
options.force
Type: Boolean
Default: false
By default, this function doesn't push a new history when the old URL is the same as new one. If you set this option true
, it will push a new history in any case.
// On http://yoursite.com/#foo historylength; //=> 1 ;historylength; //=> 1 ;historylength; //=> 2
License
Copyright (c) 2014 Shinnosuke Watanabe
Licensed under the MIT License.