首页 > 技术文章 > js 判断传入参数是域名还是地址

0c7x4 2017-11-21 11:55 原文

var get = function(url) {
		if(location.protocol === "http") {
			return url;
		}
		var reg = /^(http[s]?:\/\/)?([^\/]+)(.*)/,
		matches = url.match(reg);
		url = list.hasOwnProperty(matches[2])&&(list[matches[2]] + matches[3]) || url;
		return url;
	}

推荐阅读