问题描述
- 如何实现点击退出a标签后浏览器不能返回到之前的页面
-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Top.aspx.cs" Inherits="Admin_Top" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <link href="../css/style_new.css" rel="stylesheet" type="text/css" /> <script language="JavaScript" src="../js/jquery.js" type="text/javascript></script> <script type="text/javascript"> $(function () { //顶部导航切换 $(".nav li a").click(function () { $(".nav li a.selected").removeClass("selected") $(this).addClass("selected"); }) }) } </script> </head> <body style="background:url(../images/topbg.gif) repeat-x;"> <form id="form1" runat="server"> <div class="topleft"> <a href="main.html" target="_parent"><img src="../images/loginlogo.png" title="系统首页" /></a> </div> <div class="topright"> <ul> <li><a href="#"><asp:Label ID="Label1" runat="server"></asp:Label></a></li> <li><a href="../Login.aspx" target="_parent"">退出</a></li> </ul> </div> </form> </body> </html>
解决方案
用document.location.replace('http://ask.csdn.net/questions/241212')来转向,阻止默认的连接href跳转
<a href="http://ask.csdn.net/questions/241212">http://ask.csdn.net/questions/241212</a><br>
<a href="http://ask.csdn.net/questions/240607">http://ask.csdn.net/questions/240607</a>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script>
$('a').click(function(){
document.location.replace(this.href);
return false;
});
</script>
解决方案二:
a标签当然会跳转啦,你用ajax请求就不会跳转页面啦。改成如下
<a href="javascript:login()" target="_parent"">
然后在javascript用ajax请求实现login退出的方法。就能停留在原来的页面啦。
时间: 2024-12-10 10:54:21