[browser location和history] 简单实现了个路由[转载]
今天看了1下前面写的,好像缺乏交流性,周末再来弄吧 -0-
今天看了browser 的 location 和 history
location属性
// //location.hash 性是一个可读可写的字符串,该字符串是 URL 的锚部分(从 # 号开始的部分)
// console.log(location.host); //获得location的端口
// //或www.xxx.com止 //[[设置或返回]]当前 URL 的主机名称和端口号
//
// console.log(location.hostname); //返回服务域名
// //www.xxx.com:80 //[[设置或返回]]当前 URL 的主机名
//
// console.log(location.href); //返回该页面的url
// //www.xxx.com: //[[设置或返回]]当前显示的文档的完整 URL
// //location.href = 'baidu.com'; 调用改变当前url
//
// console.log(location.port); //端口:后的内容
// //"8080" //[[设置或返回]]或返回当前 URL 的端口部分
//
// console.log(location.protocol); //http://[[设置或返回]]当前 URL 的协议
//
// console.log(location.search); //?后的内容
// //有待研究吧,没效果 //[[设置或返回]]当前 URL 的查询部分(问号 ? 之后的部分)
// //我猜这个功能可能可以了解用户的网内轨迹
//
// //decodeURIComponent() 对编码后的 URI 进行解码:
// //就1个转码函数,转的码的作用有待研究
Location方法
// //location.assign()
// window.location = "www.baidu.com" 直接改变当前url //效果一样
// location.href = "www.baidu.com";
// location.assign('www.baidu.com');
//
// //location.replace
// //不会在 History 对象中生成一个新的记录。当使用该方法时,新的 URL 将覆盖 History 对象中的当前记录
// setTimeout(function(){
// console.log(1);
// location.replace("baidu.com")//p209 阻止用户返回上1页面
// },1000)
//
// //str.replace必须两个参数,这里的 replace 是 location 的方法
// var str = "abcdefghijklnm";
// console.log(str.replace("abcd",''));
//
// //location.reload() //这个方法会一直load,慎用
// location.reload(); //重新加载,有可能是从缓存中加载
// location.reload(true); //重新加载,从服务器重新加载
//
// setTimeout(function(){
// location.reload();
// //并且reload()调用之后的代码可能也不会执行,网络原因系统资源等因素,
// //最好放在最后一行
// return false; //没效果
// },5000)
// 个人认为这个真没必要用,reload()是会把整个文档从新加载
//
// 若需要部分组件定时更新数据,用ajax就好
// 这是写的简单定时更新数据
//history
// history.go(-1); //后退
// history.go(1); //前进1页
// history.go(2); //前进2页
//
// history.go("baidu.con"); //跳转到最近的baidu.com页面 //history.back(); //后退一页;
//history.forward(); //前进一页;
//hiseory.length; //下标0开始第1页
简单理由封装
参考:http://blog.csdn.net/sunxinty/article/details/52586556
作者:SunxHome
function Router(){
this.routes = {};
this.currentUrl = '';
};
Router.prototype.route = function(path,callback){
this.routes[path] = callback || function(){};
};
Router.prototype.refresh = function(){
this.currentUrl = location.hash.slice() || '/';
this.routes[this.currentUrl]();
};
Router.prototype.init = function(){
window.addEventListener('load',this.refresh.bind(this),false);
window.addEventListener('hashchange',this.refresh.bind(this),false)
};
window.Router = new Router();
window.router.init();
[browser location和history] 简单实现了个路由[转载]的更多相关文章
- match,location,history
哇,平常写路由时基本就是简单的按照组件给的示例写,从来没有考虑为什么,又遇见了路由相关的问题,先记录一下问题,好好捋一下,哎,好香要个大佬来带带我呀,每次遇到问题要解决好久 问题: 判断是否登录之后跳 ...
- location 、history
location.href= location.reload() history.go() 0 1 -1 history.back() history.forward() history.le ...
- location和history
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- (cljs/run-at (JSVM. :browser) "命名空间就这么简单")
前言 一个cljs文件定义一个命名空间,通过命名空间可以有效组织代码,这是构建大型系统必备的基础设施.本篇我们就深入理解cljs中的命名空间吧! 好习惯从"头"开始 每个cljs ...
- JS---BOM基本知识 (顶级对象,系统对话框,加载事件,location对象, history对象, navigator对象)
BOM JavaScript分三个部分: 1. ECMAScript标准---基本语法 2. DOM--->Document Object Model 文档对象模型,操作页面元素的 3. BOM ...
- BOM 3.1 location对象 | history对象 | navigator对象 | 定时器 | 三大系列
JavaScript分三个部分: 1. ECMAScript标准---基本语法 2. DOM--->Document Object Model 文档对象模型,操作页面元素的 3. BOM---& ...
- Location 位置 history
拆分出来地址 让地址各归其位 search案例 查找历史记录跳转
- 学习记录----简单的原生js路由
在以前的web程序中,路由字眼只出现在后台中.但是随着SPA单页面程序的发展,便出现了前端路由一说.单页面顾名思义就是一个网站只有一个html页面,但是点击不同的导航显示不同的内容,对应的url也会发 ...
- 分享php中四种webservice实现的简单架构方法及实例[转载]
[转载]http://www.itokit.com/2012/0417/73615.html 本人所了解的webservice有以下几种:PHP本身的SOAP,开源的NUSOAP,商业版的PHPRPC ...
随机推荐
- d3.js 入门指南 - 仪表盘
D3的全称是Data-Driven Documents(数据驱动的文档),是一个用来做数据可视化的JavaScript函数库,而JavaScript文件的后缀通常为.js,所以D3被称为D3.js. ...
- 【后端C#】后台通过http post 调用 webservice 的方法
定义http post 调用webservice的某个方法 /// <summary> /// http Post调用 WebService /// </summary> pu ...
- FCC---CSS Flexbox: Use the flex-direction Property to Make a Column
The last two challenges used the flex-direction property set to row. This property can also create a ...
- 磁盘修复 mount: wrong fs type running e2fsck
当服务器或PC机器的硬盘在使用一段时间后,会出现无法使用正常进行使用: 1. 当将文件系统挂载到指定的目录的时候,会出现mount 失败,如下图: [root@template ~]# mount / ...
- C语言笔记 03_常量&存储类
常量 常量是固定值,在程序执行期间不会改变.这些固定的值,又叫做字面量. 常量可以是任何的基本数据类型,比如整数常量.浮点常量.字符常量,或字符串字面值,也有枚举常量. 整数常量 整数常量可以是十进制 ...
- SpringCloud之Feign 负载均衡请求超时时间
版本声明: SpringCloud:Greenwich.SR4 SpringBoot:2.1.9.RELEASE Feign调用服务的默认时长是1秒钟,也就是如果超过1秒没连接上或者超过1秒没响应,那 ...
- (转)LSTM神经网络介绍
原文链接:http://www.atyun.com/16821.html 扩展阅读: https://machinelearningmastery.com/time-series-prediction ...
- layui table+复杂表头+合并单元格
效果图: 问题:行hover效果感觉错乱 所以改为透明色 代码: <!DOCTYPE html> <html lang="en"> <head> ...
- [转]UIPath进阶教程-6. Architecture & Publishing flow
本文转自:https://blog.csdn.net/liaohenchen/article/details/88847597 版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议, ...
- 前端开发规范:4-JS
ESLint 使用ESLint的standard规范来编写js代码 更多参考: https://github.com/standard/standard/blob/master/docs/README ...