为什么 window.location.search 为空?
1,什么是window.location?示例
URL:http://b.a.com:88/index.php?name=kang&when=2011#first
| 属性 | 含义 | 值 |
|---|---|---|
| protocol: | 协议 | "http:" |
| hostname: | 服务器的名字 | "b.a.com" |
| port: | 端口 | "88" |
| pathname: | URL中主机名后的部分 | "/index.php" |
| search: | "?"后的部分,又称为查询字符串 | "?name=kang&when=2011" |
| hash: | 返回"#"之后的内容 | "#first" |
| host: | 等于hostname + port | "b.a.com:88" |
| href: | 当前页面的完整URL | "http://www.a.com:88/index.php?name=kang&when=2011#first" |
window.location和document.location互相等价的,可以交换使用
location的8个属性都是可读写的,但是只有href与hash的写才有意义。例如改变location.href会重新定位到一个URL,而修改location.hash会跳到当前页面中的anchor(<a id="name">或者<div id="id">等)名字的标记(如果有),而且页面不会被重新加载
注意
URL:http://b.a.com:88/index.php?name=kang&how=#when=2011#first
search:"?name=kang&how=" 第一个"?"之后
//获取url参数
function GetQueryString (name)
{
var after = window.location.hash.split("?")[1];
if(after)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = after.match(reg);
if(r != null)
{
return decodeURIComponent(r[2]);
}
else
{
return null;
}
}
为什么 window.location.search 为空?的更多相关文章
- window.location属性用法及解决一个window.location.search为什么为空的问题
通常用window.location该属性获取页面 URL 地址: 1.什么是window.location? 比如URL:http://b.a.com:88/index.php?name=kang& ...
- window.location.search 在url中有?name=value时仍为‘’的情况
1,当页面有hash#值 而?name=value在hash #的串后面将会有这种结果 2,为什么 window.location.search 为空? 答:注意上面的search和hash的区别,如 ...
- window.location.search 为何在url 带# 号时获取不到 ?
我们在获取url参数时,会常常用到截取参数 getUrlParam(name) { const reg = new RegExp('(^|&)' + name + '=([^&]*)( ...
- window.location.search
http://i.cnblogs.com/EditPosts.aspx?opt=1&opt2=x 就拿上面这个URL来说window.location.search的返回值为opt=1& ...
- window.location.search作用
window.location.search.substr(1).split("&") 这里面的相关属性和时间还有参数能具体说明一下吗?window.location wi ...
- (转)window.location.search的用法
location.search是从当前URL的?号开始的字符串如:http://www.51js.com/viewthread.php?tid=22720它的search就是?tid=22720 通过 ...
- [置顶] 初识window.location.search
window.location.search是从当前URL的?号开始的字符串 如:http://www.domain.com/item?id=0064014 它的search就是?id=0064014
- 通过window.location.search获取页面url传递的参数
function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...
- javascript中window.location.search的用法和作用。
用该属性获取页面 URL 地址: window.location 对象所包含的属性 属性 描述 hash 从井号 (#) 开始的 URL(锚) host 主机名和当前 URL 的端口号 hostnam ...
随机推荐
- Bookstrap4 学习(一)
容器 container 是最基本的lagyout 元素, 并且当使用默认的Grid 系统时, containers 是必须的. <div class="container" ...
- Kettle系列文章二(安装配置Kettle+SqlServer+简单的输入输出作业)
一.下载 Kettle下载地址:https://community.hitachivantara.com/docs/DOC-1009855 下拉到DownLoad,点击红框中的链接进行下载.. 二.解 ...
- [android] socket在手机上的应用
1.手机助手 1.1 USB链接 可以读取手机的PID和VID,确定唯一的设备,可以给手机安装对应的驱动等 socket在固定端口通信 1.2 WIFI链接 pc在电脑在整个网段发送UDP数据包,手机 ...
- 一台电脑上运行两个tomcat
1.建立两个文件夹,tomcat1,tomcat2,分别在里面放入tomcat7文件(非安装版) 2.改配置 tomcat1中的配置就不用改了,直接用默认配置 tomcat2中的配置要改要,改conf ...
- thinkphp session设置
<?php namespace Home\Controller; use think\Controller; /*登录*/ class LoginController extends Publi ...
- thinkphp怎么把数据库中的列的值存到下拉框中
1. 先去数据库中查值,查询整个数据表,结果为二维数组. $project = M("project"); $cell = $project->where(array('st ...
- NOIP2017:列队
Sol 考场上: 这不是送\(50\)吗,\(Q^2\)递推就好了 然后,怎么又送\(20\)分??? \(woc\),只有半个小时了,顺利没调出来只有\(50\)分 考后: 神\(TM\)一个大于号 ...
- webapp 的简单开发
web app 的技术平台很多,如adobe phonegap.sencha touch.appcan(国产).dcloud(国产)平台.我选择了dcloud平台,原因:简单,容易上手. web ap ...
- 1-3 Sass 语法、编译、调试
Sass 语法格式 这里说的 Sass 语法是 Sass 的最初语法格式,他是通过 tab 键控制缩进的一种语法规则,而且这种缩进要求非常严格.另外其不带有任何的分号和大括号.常常把这种格式称为 Sa ...
- flexviewer infowindow背景问题
flexiewer里遇到的一些问题 infoWindowRenderer问题 在arcgis api for flex中要设置infowindow的外观很容易,只需要在编写一下css文件即可,就如 e ...