js-url操作记录
2024-09-05 21:33:09
禁用回退&开启回退
// 必须声明方法 否则无法删除此监听器
function backCommon() {
history.pushState(null, null, document.URL);
} // 禁用浏览器回退页面操作
history.pushState(null, null, document.URL);
window.addEventListener('popstate', backCommon); // 开启浏览器回退页面操作
window.removeEventListener('popstate', backCommon);
window.location.href = "/word/show";
禁用回退&无法开启回退
// 如果你希望用户不用有返回功能 可缩写如下 或使用location.replace('url')跳转链接
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
url常用方法
// 获取整个url或跳转url
window.location.href; // 设置或获取url问号后参数
window.location.search; // 设置或获取href属性中在井号后的值
window.location.hash; // 设置或获取url的协议
window.location.protocol; // 设置或获取url的hostname localhost/user?id=1返回'/user'
window.location.hostname; // 设置或获取url端口号
window.location.port;
js常用返回方法
// 返回上页
history.go(-1);
// 返回上上页
history.go(-2);
// 返回上页 有人说back返回会刷新上个页面但我的操作过程中页面并没有刷新
history.back();
// 返回上页
history.back(-1); // 返回下一页
history.go(1);
// 返回下一页
history.forward();
// 产生点击前进按钮的效果 抵消用户点击后退按钮所产生事件
istory.forward(1);
刷新页面
history.go(0); location.reload(); location = location; // 加载新页面可以url可以前进后退
location.href = location.href;
// 加载新页面可以url可以前进后退 等同如上操作
location.assign(location);
// 替换当前页 清除url历史记录 无法前进后退
location.replace('http://www.baidu.com')
// 此方法可以使当前页面失去前进后退功能
location.replace(this.href);
location.replace(location); document.execCommand('Refresh'); window.navigate(location); document.URL = location.href;
js获取url中的参数
function geUrltParam(paramKay) {
let reg = new RegExp("(^|&)" + paramKay + "=([^&]*)(&|$)", "i");
let r = location.search.substr(1).match(reg);
return r == null ? null : decodeURI(r[2]);
} // localhost:8080/index?openId=xxxx
var openId = getQueryString("openId");
最新文章
- 如何在 ASP.NET 4.6 与 IIS10 中运用 HTTP/2 ?
- 学堂在线 UWP 首版
- fstream 中判断是否成功打开文件
- sql server 常用脚本(日常查询所需)
- gradle构建android项目
- NodeJs - 序列化
- POJ 3268 Silver Cow Party (双向dijkstra)
- WCF分布式开发步步为赢(11):WCF流处理(Streaming)机制
- LaTeX中用BibTex管理参考文献
- mysql 中文配置(转)
- 线性规划问题的matlab求解
- 理解Python的with as语句
- [extjs(1)]MyEclipse2014安装ext4插件Spket
- Win10系统下的Tomcat7.0配置
- hdu5904 LCIS
- Unity导航 (寻路系统Nav Mesh Agent)
- linux (ubuntu) 命令学习笔记
- ssh-keygen 基本用法
- SQL Server 性能优化实战系列(二)
- ota升级动画背景色修改
热门文章
- 你不知道的props和state
- socket keepalive 服务端异常断线
- Manacher || BZOJ 2342: [Shoi2011]双倍回文 || Luogu P4287 [SHOI2011]双倍回文
- C#基础知识之GC 垃圾回收
- YUM源使用阿里镜像
- bzoj3011 [Usaco2012 Dec]Running Away From the Barn 左偏树
- 7.docker私有registry
- 【NOIP2013模拟联考5】军训
- 【leetcode】410. Split Array Largest Sum
- 1. svn 简介