function UrlOption(url) { this.url = url || ''; this.init(); this.change = function (url) { this.url = url this.init(); } this.getParams = function (name) { var list = this.search.split('&'),params={},param list.forEach(function (v) { var param = /^([^&#*]*)+=([^&#]*)+/.exec(v) if(param[1]) params[param[1]] = param[2]?param[2]:'' }) return name?params[name]:params } } UrlOption.prototype.init = function() { if(!this.url) return ''; this.search = this.url.split('?')[1] var host = /^([a-zA-Z]+:\/\/)?((www\.)?[^#&\/:]+(:(\d{1,5}))?)(\/.+)?$/.exec(this.url), protocol = /^([a-zA-Z]+):\/\/(www\.)?.+$/.exec(this.url) this.host = host ? host[2]:'' this.protocol = protocol ? protocol[1] : '' this.port = host ? host[5] : '' this.pathname = host ? host[6] : '' } var opt = new UrlOption('http://www.segmentf.sdfault.us:50/a/1190000004641602?12=12&23=23#s'); console.log(opt)