JS 实现页面跳转的几种方法
JS 实现页面跳转的几种方法
要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码
JS跳转大概有以下几种方式:
第一种:(跳转到b.html)
<script language="javascript" type="text/javascript">window.location.href="b.html";</script>
第二种:(返回上一页面)
<script language="javascript">window.history.go(-1);</script>
第三种:
<script language="javascript">window.navigate("b.html");</script>
第四种:
<script language="JavaScript">self.location=’b.html’;</script>
第五种:
<script language="javascript">top.location=’b.html’;</script>
页面传值:
第一个页面
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><SCRIPT LANGUAGE="JavaScript">function test(){var s = document.getElementById("txt");location.href="test2.html?"+"txt="+encodeURI(s.value);}</SCRIPT><body><input type="text" id="txt"></br><input type="button" value="TEST" onclick="test()"/></body></html>
第二个页面
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><script language="javascript" type="text/javascript">var loc = location.href;var n1 = loc.length;//地址的总长度var n2 = loc.indexOf("=");//取得=号的位置var id = decodeURI(loc.substr(n2+1, n1-n2));//从=号后面的内容alert(id);//document.write(id)</script></body></html>
注:中文传输:可以在页面a用encodeURI 编码url 在b页面用decodeURI解码url
使用 JS 实现页面跳转的几种方式总结
第一种:使用JS跳转页面
1)跳转带参
<script language="javascript" type="text/javascript">window.location.href="jingxuan.do?backurl=" + window.location.href; </script>
2)跳转无参
<script>window.location.href='http://blog.yoodb.com';</script>
第二种:返回上一次预览界面
<script language="javascript">alert("返回");window.history.back(-1);</script>
HTML页面嵌套
<a href="javascript:history.go(-1)">返回上一步</a><a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>
第三种:button按钮添加事件跳转
<input name="前端知音" type="button" value="前端知音" onClick="location.href='login.do'">
第四种:在新窗口打开
<a href="javascript:" onClick="window.open('login.do','','height=500,width=611,scrollbars=yes,status=yes')">新窗口</a>
第五种:通过meta设置跳转页面
<head><!--只刷新不跳转 --><meta http-equiv="refresh" content="5"><!--定时跳转 --><meta http-equiv="refresh" content="5;url=index.html"> </head>
参考文章:
https://www.cnblogs.com/lyggqm/p/5688028.html
https://blog.csdn.net/afreon/article/details/119617930
https://blog.csdn.net/yiye2017zhangmu/article/details/82782374
JS 实现页面跳转的几种方法相关推荐
- js 控制页面跳转的5种方法
js 控制页面跳转的5种方法 编程式导航: 点击跳转路由,称编程式导航,用js编写代码跳转. History是bom中的History.back是回退一页Histiory.go(1)前进一页Histo ...
- Jsp页面跳转和js控制页面跳转的几种方法
Jsp 页面跳转的几种方法 1. RequestDispatcher.forward() 在服务器端起作用,当使用forward()时,Servlet engine传递HTTP请求从当前的Servle ...
- js中实现页面跳转的几种方法
按钮式: 1 <INPUT name="pclog" type="button" value="GO" onClick="l ...
- 本地html自动跳转,HTML页面跳转的5种方法
下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件. 1) html的实现 优点:简单 缺点:Struts Tiles中 ...
- php实现页面跳转的几种方法(实例分享)
发布:theboy 来源:net [大 中 小] 转自:http://www.jbxue.com/article/2366.html php 页面跳转的几种方法 方法一.header()函 ...
- php页面跳转的方法,PHP实现页面跳转的四种方法
PHP实现页面跳转的四种方法 发布时间:2020-05-20 11:36:01 来源:亿速云 阅读:172 作者:Leah 今天小编就为大家分享PHP实现页面跳转的四种方法.小编觉得挺实用的,为此分享 ...
- 视频直播网站源码,uniapp页面跳转的几种方法和区别
视频直播网站源码,uniapp页面跳转的几种方法和区别 保留当前页面,可跳转到非 tabBar 页面,使用uni.navigateBack可以返回到原页面(可传参) uni.navigateTo({u ...
- JQuery实现页面跳转 页面跳转的七种方法
<mce:script type="text/javascript"><!-- $(function(){ var pn = $("#gotopagen ...
- JS页面跳转的几种方法
来介绍一下我所用的JS跳转页面的方法 第一种:这是最常用的了 window.location.href <script language="javascript" type= ...
最新文章
- 详细谈电脑ip、域名、内网、外网、localhost、127.0.0.1、网关等通讯基础知识(易懂)
- Nature子刊:宏基因组中挖掘原核基因组的分析流程
- 两院院士评选2020年中国、世界十大科技进展揭晓,「机器学习模拟上亿原子」等入选 | AI日报...
- useradd -g mysql mysql_Linux —— useradd -g mysql mysql解析及useradd详解
- java thumbnails 中心点_java Thumbnails 图片处理的使用
- 如何用cocoapods 来管理项目中的第三方框架?
- leetcode632. 最小区间(堆+多指针)
- 五年级信息技术上册教案计算机主机探秘,第1课信息与信息技术探秘教案
- html盒子模型 1209
- SQL SERVER的字段类型说明
- LeetCode---binary-tree-inorder-traversal
- 使用Python爬取mobi格式电纸书
- 日本「AI 鱼脸识别」项目,每分钟识别 100 条,有望让渔民不再“摸鱼”
- MailBee电子邮件发送接收pop3/IMAP4/SMTP套件MailBee Objects下载
- 从C#程序中调用非受管DLLs
- 远程仓库之GitHub介绍
- 软件测试基础知识 + 面试理论(超详细)
- 场景文字检测——CTPN模型介绍及代码实现
- UG软件_NX1926中文版网盘下载链接+安装教程
- java 解析dex_将DEX反编译成Java源代码