location和window.open的小结--(获取url里的各种玩意以及页面)
来源:互联网 发布:淘宝店策划方案 编辑:程序博客网 时间:2024/05/21 17:10
window.location的样子
示例
URL:http://d.a.com:9000/index.html?name=ddd&when=2017#first
方法
location.assign( url )
location.assign('http://www.baidu.com'); 等同于 window.location = 'http://www.baidu.com'
这种方式会讲新地址放到浏览器历史栈中,意味着转到新页面后“后退按钮”仍可以回到该页面。
location.replace( url )
与assign方法一样,但会从浏览器历史栈中删除本页面,也就是说跳转到新页面后“后退按钮”不能回到该页面。目前IE、Chrome只是简单的跳转,只有Firefox会删除本页面的历史记录。
location.reload( force )
重新载入当前页面。force为true时从服务器端重载;false则从浏览器缓存中重载,默认值false
Window.open的参数小结(参书改编) 先看一个例子:
[javascipt:]window.open("Webpage.asp?",Derek,"height=100,width=100,status=yes,toolbar=yes, menubar=no,location=no");此语句打开一个新窗口,页面为webpage.asp,参数为var,名字为Derek,高为100,宽为100,显示状态栏和工具条,不显示菜单和地址。
具体总结的各个属性参数如下:
window = object.open([URL ][, name ][, features ][, replace]]]])
URL:新窗口的URL地址
name:新窗口的名称,可以为空
featurse:属性控制字符串,在此控制窗口的各种属性,属性之间以逗号隔开。
fullscreen= { yes/no/1/0 } 是否全屏,默认no
channelmode= { yes/no/1/0 } 是否显示频道栏,默认no
toolbar= { yes/no/1/0 } 是否显示工具条,默认no
location= { yes/no/1/0 } 是否显示地址栏,默认no
directories = { yes/no/1/0 } 是否显示转向按钮,默认no
status= { yes/no/1/0 } 是否显示窗口状态条,默认no
menubar= { yes/no/1/0 } 是否显示菜单,默认no
scrollbars= { yes/no/1/0 } 是否显示滚动条,默认yes
resizable= { yes/no/1/0 } 是否窗口可调整大小,默认no
width=number 窗口宽度(像素单位)
height=number 窗口高度(像素单位)
top=number 窗口离屏幕顶部距离(像素单位)
left=number 窗口离屏幕左边距离(像素单位)
关于本题中,第二个参数的详解:
name可以为:
_blank 表示新开一个窗口,
_parent表示父框架窗口,
_self表示覆盖该窗口,
xxx表示覆盖名字为xxx的窗口
(每个窗口都可以给他命名)
不能为省略,可以为空!
获取url中携带参数的方法
/*返回一个对象,包含url中所有参数*/
const getRequest = function() {let url = window.location.search; //获取url中"?"符后的字串let theRequest = new Object();if (url.indexOf("?") != -1) {let str = url.substr(1);if (str.indexOf("&") != -1) {let strs = str.split("&");for (let i = 0; i < strs.length; i++) {theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);}} else {theRequest[str.split("=")[0]] = unescape(str.split("=")[1]);}}return theRequest;}/*根据要获取的参数名称,返回url中对应参数值*/(name)=> { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); var r = decodeURIComponent(window.location.search.substr(1)).match(reg); if (r != null) return unescape(r[2]); return null;}
0 0
- location和window.open的小结--(获取url里的各种玩意以及页面)
- jquery 打开页面window.location和window.open的区别
- javascript 打开页面window.location和window.open的区别
- window.location和window.open()的区别
- window.location 的常用属性(获取当前页面的url)
- js 中实现页面跳转的方法(window.location和window.open的区别)
- javascript 打开页面window.location.href和window.open的区别
- JavaScript获取从上个页面传过来的url参数:GetQueryString()方法和window.location.search方法
- js 获取当前页面的url等内容 window.location系列
- window.location与window.open()的区别 "top.location.href"是最外层的页面跳转
- 用window.location和window.open做链接的区别
- window.location.href 和 window.open 的区别
- 用window.location和window.open做链接的区别
- window.location和window.open的区别[JavaScript]
- window.open和window.location.href的几种用法
- window.open和window.location.href的几种用法
- 用window.location和window.open做链接的区别
- 用window.location和window.open做链接的区别
- Java中如何结束线程
- 67. @Transactional的类注入失败【从零开始学Spring Boot】
- 集成腾讯ilive音视频通讯,实现医生和患者实时在线音视频沟通
- Java中通过TCP协议发送和接收数据-Socket编程
- http
- location和window.open的小结--(获取url里的各种玩意以及页面)
- weex中web标签加载手机端页面适配
- MapReduce 进阶:Partitioner 组件
- http请求
- 利用NuGet安装IKVM.OpenJDK.Core
- android studio 相关错误!
- Pessimistic and Optimistic locking
- 笨蛋的难题(一)
- yum出错:“Error: Cannot find a valid baseurl for repo: base”