Skip to content

Instantly share code, notes, and snippets.

@lostsh
Created June 4, 2021 15:34
Show Gist options
  • Save lostsh/c9217981905f85e450a1b6993ae46500 to your computer and use it in GitHub Desktop.
Save lostsh/c9217981905f85e450a1b6993ae46500 to your computer and use it in GitHub Desktop.
Ugly JS code to handle some url params
/**
* Return the page from the url
* like https://.../index.html#page=X : return X
* If page not found return 0
*/
function urlGetPage(){
var params = {
'page' : 0
};
var pageUrl = window.location.href;
if(pageUrl.indexOf("#page=") > 0){
if(pageUrl.indexOf("#", pageUrl.indexOf("#")+1) > 0){
params.page = parseInt(pageUrl.substr(pageUrl.indexOf("#page=")+6, pageUrl.indexOf("#", pageUrl.indexOf("#page=")+6)));
}else if(pageUrl.indexOf("#")+6 < pageUrl.length){
params.page = parseInt(pageUrl.substr(pageUrl.indexOf("#page=")+6, pageUrl.length));
}
if(isNaN(params.page) || params.page < 0) params.page = 0;
}
return params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment