fontendNote
  • docs
  • sources
    • others
      • 数据结构与算法
        • 第一章:绪论
      • 英语阅读积累词汇
      • git
        • 常用Git命令与技巧
        • sourcetree一直提示输入密码的终极解决方案(亲测有效)
      • case
        • 曲线编辑器
          • canvas实现曲线编辑器
      • 计算机常见单词
    • ts
      • ts 配置参考(带注释)
  • source
    • _about
      • 你可能不知道的 vscode 使用技巧
    • _posts
      • css
        • CSS 优化细则
        • sass
          • sass学习笔记
        • 《css世界》书摘
      • js
        • dom
          • 常用js页面跳转方式
          • 跨浏览器的javascript中鼠标滚轮事件
        • performance
          • js性能优化注意事项
      • node
        • npm-package
          • chokidar
        • node中获取正在运行的全部进程数据
        • node中对路径分隔符的兼容性处理
      • tools
        • 你可能不知道的 vscode 使用技巧
      • leetcode
        • 无重复字符的最长子串
        • 题目
  • scaffolds
    • page
    • post
    • draft
Powered by GitBook
On this page

Was this helpful?

  1. source
  2. _posts
  3. js
  4. dom

常用js页面跳转方式

工作中会常用到必须用js的页面跳转,刷新,总结了一下常用的js跳转页面的方法和页面刷新及页面自动刷新,js引入js文件的常用技巧,便于查阅。

1.window.location.href方式

window.location.href="target.aspx";

2.window.navigate方式跳转

 window.navigate("target.aspx");

3.self.location方式实现页面跳转,和下面的top.location有小小区别

self.location='target.aspx';

4.top.location

top.location='target.aspx';

5.不推荐这种方式跳转

 alert("返回");  
 window.history.back(-1);

6.小技巧(JS引用JS):

if (typeof SWFObject == "undefined") {    
    document.write('<scr' + 'ipt type="text/javascript" src="/scripts/swfobject-1.5.js"></scr' + 'ipt>');  
}

7.Javascript刷新页面的几种方法:

history.go(0)  
location.reload()  
location=location  
location.assign(location)  
document.execCommand('Refresh')  
window.navigate(location)  
location.replace(location)  
document.URL=location.href

8.自动刷新页面的方法:页面自动刷新:把如下代码加入head区域中,其中20指每隔20秒刷新一次页面.

<meta http-equiv="refresh" content="20">
<meta http-equiv="refresh" content="20;url=http://www.qianduandu.com">

10.如果想关闭窗口时刷新或者想开窗时刷新的话,在中调用以下语句即可。

<body onload="opener.location.reload()"> 开窗时刷新   
<body onUnload="opener.location.reload()"> 关闭时刷新 
window.opener.document.location.reload()
PreviousdomNext跨浏览器的javascript中鼠标滚轮事件

Last updated 5 years ago

Was this helpful?

9.页面自动跳转:把如下代码加入head区域中,其中20指隔20秒后跳转到

http://www.qianduandu.com页面