Get the domain of URL, and other params.
Usage:
const ret1 = getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');const ret2 = getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);const ret3 = getDomain('http://example.com:7890/test/thanks', ['hostname']);const ret4 = getDomain('http://example.com:7890/test/thanks', ['host']); // With Portconst ret5 = getDomain('http://example.com:7890/test/thanks', ['origin']);const ret6 = getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);console.log(ret1);console.log(ret2);console.log(ret3);console.log(ret4);console.log(ret5);console.log(ret6); Copy
const ret1 = getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');const ret2 = getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);const ret3 = getDomain('http://example.com:7890/test/thanks', ['hostname']);const ret4 = getDomain('http://example.com:7890/test/thanks', ['host']); // With Portconst ret5 = getDomain('http://example.com:7890/test/thanks', ['origin']);const ret6 = getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);console.log(ret1);console.log(ret2);console.log(ret3);console.log(ret4);console.log(ret5);console.log(ret6);
Output:
example.com example.com/test/thanks example.com example.com:7890 http://example.com:7890 http://example.com:7890/test/thanks?id=1 Copy
example.com example.com/test/thanks example.com example.com:7890 http://example.com:7890 http://example.com:7890/test/thanks?id=1
Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
Get the domain of URL, and other params.
Usage:
Output: