欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

JavaScript实现页面跳转的几种常用方式

时间:2021-03-13 09:47:09|栏目:JavaScript代码|点击:

本文实例讲述了JavaScript实现页面跳转的几种常用方式。分享给大家供大家参考,具体如下:

第一种:

<script language="javascript" type="text/javascript"> 
    window.location.href="login.jsp?backurl="+window.location.href; 
</script> 

第二种:

<script language="javascript">
    alert("返回");
    window.history.back(-1);
</script> 

第三种:

<script language="javascript">
    window.navigate("top.jsp");
</script>

第四种:

<script language="JavaScript">
    self.location='top.htm';
</script>

第五种:

<script language="javascript">
    alert("非法访问!");
    top.location='xx.jsp';
</script>

javascript中弹出选择框跳转到其他页面

<script language="javascript">
<!--
function logout()...{
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{
window.location.href="logout.asp?act=logout"
}
}
-->
</script>

javascript中弹出提示框跳转到其他页面

<script language="javascript">
<!--
function logout()...{
alert("你确定要注销身份吗?");
window.location.href="logout.asp?act=logout"
}
-->
</script>

补充:window.location="";和 location.replace("");有什么区别?

这两个都能让网页导向令一个网址,那么有什么区别呢?比如能带参数,不能带参数之类的.
 Replace?还是Reload()?
好像没什么区别吧?没试过
 
replace(),reload()是重新加载本页,而replace()可以导向另外一个URL
 
给你举个例子:

我们现在有3个页面(a.html, b.html, c.html).
默认打开a.html页面,然后在a.html页面中通过一个链接转向a.html页面。

现在,我在b.html页面中用window.location.replace("c.html");与用window.location.href("c.html");分别进入c.html页面.

从用户界面来看是没有什么区别的,但是现在c.html页面有一个“返回”按钮,
用window.location.href("c.html");

进入c.html页面时,c.html页面中的调用window.history.go(-1);wondow.history.back();进入c.html页面时,一点这个"返回"按钮就要返回b.html页面的话,
而如果用window.location.replace("c.html");进入c.html页面的话,
c.html页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到a.html.
 
因为window.location.replace("c.html");是不会向服务器发送请求而进行跳转,而window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以会跳到系统默认页面a.html 。

window.location.href("c.html");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以就可以返回到b.html。

希望本文所述对大家JavaScript程序设计有所帮助。

上一篇:浅谈js中用$(#ID)来作为选择器的问题(id重复的时候)

栏    目:JavaScript代码

下一篇:layui实现下拉复选功能的例子(包括数据的回显与上传)

本文标题:JavaScript实现页面跳转的几种常用方式

本文地址:http://www.codeinn.net/misctech/79699.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有