如何使用javascript或jQuery获得没有IP或主机名的URL地址?
我希望得到一个没有IP或主机名的URL地址,例如如何使用javascript或jQuery获得没有IP或主机名的URL地址?,javascript,jquery,Javascript,Jquery,我希望得到一个没有IP或主机名的URL地址,例如 image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1 但是window.location.href返回以下结果 http://192.168.0.149:9031/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefil
image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1
但是window.location.href
返回以下结果
http://192.168.0.149:9031/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1
使用
路径名
属性
window.location.pathname
使用pathname
属性
window.location.pathname
如下所示。使用split()
方法将字符串拆分为数组
var url='1〕http://192.168.0.149:9031/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1';//window.location.href
var path=url.split('/');
警报(路径[3])代码>如下。使用split()
方法将字符串拆分为数组
var url='1〕http://192.168.0.149:9031/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1';//window.location.href
var path=url.split('/');
警报(路径[3])
您可以使用URL
构造函数,或位置.pathname
和搜索
var loc=”http://192.168.0.149:9031/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1";
var url=新的url(loc);
var pathSearch=url.pathname.slice(1)+url.search;
console.log(路径搜索)
您可以使用URL
构造函数,或位置.pathname
和搜索
var loc=”http://192.168.0.149:9031/image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1";
var url=新的url(loc);
var pathSearch=url.pathname.slice(1)+url.search;
console.log(路径搜索)代码>谢谢!但是window.location.pathname只返回image.htm!我希望返回image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1@HelloCWwindow.location.pathname+window.location.search
谢谢!但是window.location.pathname只返回image.htm!我希望返回image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1@HelloCWwindow.location.pathname+window.location.search