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跳转页面

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://www.cnblogs.com/captainbed

原文地址:https://www.cnblogs.com/siwnckhhw/p/10184295.html

时间: 2024-08-30 02:37:00

JavaScript 页面跳转的几种方式的相关文章

JavaScript实现页面跳转的五种方式

JavaScript实现页面跳转的五种方式 第一种:<script type="text/javascript" language="javascript"> window.location.href="login.jsp?backurl="+window.location.href;</script> 第二种:<script type="text/javascript" language=&qu

实现前端页面跳转的几种方式

实现前端页面跳转的几种方式 推荐使用 <script language='javascript'> document.location = 'http://mail.qq.com/domain/longtimenosee.cc' </script> 相关阅读 http://www.jb51.net/article/25403.htm http://my.oschina.net/ososchina/blog/340854

php页面跳转的几种方式

@: PHP页面跳转的三种方式 第一种方式:header() header()函数的主要功能是将HTTP协议标头(header)输出到浏览器. 语法: void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) 可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换. 第二个可选参数http_response_code强制将HTTP相应代码设为指定值. he

web项目中实现页面跳转的两种方式

<a href="javascript:"></a>跳转在网页本身,URL不改变 <a href="#"></a> 跳转在网页本身,URL 改变 java web项目中实现页面跳转的主要方式有两种:第一种,<% response.sendRedirect("index.jsp");%>第二种<jsp:forward page="index.jsp"/>我做

php中实现页面跳转的几种方式

亲测,not复制粘贴 PHP中实现页面跳转有一下几种方式,看了几个人写的不是很条理,自己整理一下 在PHP脚本代码中实现 <?php header("location:url地址") ?> 例如 <?php header("location:helloworld.php")?> 页面会立即跳转,因为header执行了location重定向 延迟跳转(比如登陆成功后会有几秒钟等待时间,然后跳转到了其他页面) <?php header(&q

PHP 页面跳转的三种方式

第一种方式:header() header()函数的主要功能是将HTTP协议标头(header)输出到浏览器. 语法: void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) 可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换. 第二个可选参数http_response_code强制将HTTP相应代码设为指定值. header函数中Location类

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

通过js或者html或者PHP等动态程序都可以方便的实现跳转,这里搜集了几种页面跳转的方式 js方式的页面跳转 1.window.location.href方式 <script language="JavaScript" type="text/javascript"> window.location.href="http://www.dayanmei.com/"; </script> 2.window.navigate方式

页面跳转的几种方式

第一种: <script language="javascript"> window.location.href="index.php"; //比较常用的方法,没什么可解释的,后面直接跟指定要跳转的地方. </script> 第二种: <script language="javascript"> alert("返回"); window.history.back(-1); //类似于按钮,参数

js实现页面跳转的几种方式

第一种: <script language="javascript" type="text/javascript"> window.location.href="xx.jsp?backurl="+window.location.href; </script> 另外一种: <script language="javascript"> alert("返回"); window.