Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL Renaming via JavaScript
- $links.on('click', function(event) {
- var href = $(this).attr('href'),
- chapter = (href.search(/chapter/) !== -1) ? href.substring(8) : 0;
- _saveState(chapter);
- return false;
- });
- $container.on('click', 'article.hs-content', function(event) {
- var id = $(this).attr('id'),
- chapter = (id.search(/chapter/) !== -1) ? id.substring(7) : 0;
- _saveState(chapter);
- return false;
- });
- _saveState = function(chapter) {
- // adds a new state to the history object
- // this will trigger the statechange on the window
- if (History.getState().url.queryStringToJSON().chapter !== chapter) {
- History.pushState(null, null, '?chapter=' + chapter);
- }
- },
- History.pushState(null, null, '?chapter=' + chapter);
- _saveState = function(chapter) {
- // adds a new state to the history object
- // this will trigger the statechange on the window
- if (History.getState().url.queryStringToJSON().chapter !== chapter) {
- var page;
- if(chapter == 1)
- page = "/about";
- else if(chapter == 2)
- page = "/services";
- else
- page = '?chapter=' + chapter;
- History.pushState(null, null, page);
- }
- },
Add Comment
Please, Sign In to add comment