Skip to content

Instantly share code, notes, and snippets.

@huobazi
Created June 29, 2016 10:30
Show Gist options
  • Save huobazi/959d38b1a488c1d0aa4fa44d2e2e7d2d to your computer and use it in GitHub Desktop.
Save huobazi/959d38b1a488c1d0aa4fa44d2e2e7d2d to your computer and use it in GitHub Desktop.
Zepto or jQuery getUrlParam
$.fn.getUrlParam = function(j) {
var l = new RegExp("(^|&)" + j + "=([^&]*)(&|$)");
var k = window.location.search.substr(1).match(l);
if (k != null) {
if (/^[\u4e00-\u9fa5]+$/.test(decodeURIComponent(k[2]))) {
return k[2];
} else {
return $("<div/>").text(k[2]).html();
}
}
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment