Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript或jQuery获得没有IP或主机名的URL地址?_Javascript_Jquery - Fatal编程技术网

如何使用javascript或jQuery获得没有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

我希望得到一个没有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&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@HelloCW
window.location.pathname+window.location.search
谢谢!但是window.location.pathname只返回image.htm!我希望返回image.htm?diskindex=0&diskcount=2&sortby=0&view=0&imagefilter=1&sizemore=1@HelloCW
window.location.pathname+window.location.search