JS获取url链接字符串 location.href
(编辑:jimmy 日期: 2025/5/11 浏览:3 次 )
js获取url链接字符串:location.href
可以对其进行截取,从而获取传送的参数,常用如下:
location.href.indexOf("?")------获取?的index值。
注意:这里的location.href可不是指的现在地址栏里的地址,而是页面实际的地址。
另外,一些题外话:
C#中获取字符所在位置的索引,也是用IndexOf来获取。
sqlserver中获取索引,就不同了:
第一种:
select * from dbo.users where CharIndex('2',mainsubjects)>0
第二种:
select * from dbo.users where patIndex('%2%',mainsubjects)>0
我使用通过判断栏目,来确定广告是否应该显示:
只有https://www.jb51.net/codes/目录的内容才显示广告:
复制代码 代码如下:
if(location.href.indexOf("https://www.jb51.net/codes/")>-1){
alert('ok');
}
可以对其进行截取,从而获取传送的参数,常用如下:
location.href.indexOf("?")------获取?的index值。
注意:这里的location.href可不是指的现在地址栏里的地址,而是页面实际的地址。
另外,一些题外话:
C#中获取字符所在位置的索引,也是用IndexOf来获取。
sqlserver中获取索引,就不同了:
第一种:
select * from dbo.users where CharIndex('2',mainsubjects)>0
第二种:
select * from dbo.users where patIndex('%2%',mainsubjects)>0
我使用通过判断栏目,来确定广告是否应该显示:
只有https://www.jb51.net/codes/目录的内容才显示广告:
复制代码 代码如下:
if(location.href.indexOf("https://www.jb51.net/codes/")>-1){
alert('ok');
}
下一篇:window.location.href中url中数据量太大时的解决方法