js 去掉url域名的三种方法

方法一:

var url = "http://blog.csdn.net/jungsagacity/article/details/7645580";

url = '/' + url.split('/').slice(3).join('/');

方法二:

var url = "http://blog.csdn.net/jungsagacity/article/details/7645580";

url = url.replace(/^http:\/\/[^/]+/, "");

方法三:

var a = document.createElement('A');a.href = 'http://blog.csdn.net/jungsagacity/article/details/7645580';
console.log(a.pathname)

你可能感兴趣的:(js 去掉url域名的三种方法)