javascript - JS get param from url hash -


console.log(_get("appid")); 

in fucn _get need check if param exist , return if exist.

function _get(paramname) {     var hash = window.location.hash; // #appid=1&device&people=      //this needs not static     if (/appid=+\w/.test(window.location.hash)) {         //and somehow parse , return;     }     return false; } 

i expect see 1 in console , if console.log(_get("device")) or people null

you need use string.match , pass in regexp object instead:

function _get(paramname) {     var pattern = paramname + "=+\w";     return (window.location.hash.match(new regexp(pattern, 'gi'))) != null; } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -