darkblue

博客园 首页 新随笔 联系 订阅 管理
今天,同事问我一个问题,如何返回调用页而不是固定的页面。经过查阅帮助,得到如下解决方式:
<html xmlns="http://www.w3.org/TR/REC-html40" xmlns:v="urn:schemas-microsoft-com:vml"
 xmlns:o="urn:schemas-microsoft-com:office:office">
 <head>
  <meta http-equiv="Content-Language" content="zh-cn">
  <title>实验室信息管理系统</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  <script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
  <style type="text/css"> img{cursor: hand }
 /*img:visited {color: blue}
 已被访问过的链接 蓝色 */ /*img:hover {size:20}
 /* 鼠标悬浮在上的链接 红色 */ /*img:active {color: green}
 鼠标点中激活链接 绿色 */ /*img{ text-decoration: none}
 */
 </style>
 
 </head>
 <body background="pic/probkgnd.gif" style="background-attachment: fixed" bottommargin=0>
  <div align= center >
   <table id="table1" style="border-style:solid; border-collapse:collapse" height="587" width="873" bgColor="#ffffff" border="0" cellpadding="0">
    <tr>
     <td width="580" colSpan="2" height="107">
      <p align="center">
       <img border="0" src="pic/800lims_main_r1_c1.jpg" width="873" height="107"></p>
     </td>
    </tr>
    <tr>
     <td width="100%" height="40" bordercolor="#003366" align="center" style="border-bottom: 0px dotted #000066" background="pic/800lims_main_tzcx_1.jpg" colspan="2">
       </td>
    </tr>
    <tr>
     <td width="28%" height="388" bordercolor="#003366" align="center"  valign=top style="border-bottom: 0px dotted #000066" background="pic/800lims_main_tzcx2_c1.jpg">
      <table border="0" width="96%" id="table2" height="377">
       <tr>
        <td align="left" height="29">
        <font size="2">&nbsp;
        <a target="aa" href="TZ_Gzlfx.htm">
        <span style="text-decoration: none">
        <font color="#000000">
        <img border="0" src="pic/table.gif" width="21" height="18">&nbsp;
        罐质量分析</font></span></a></font></td>
       </tr>
       <tr>
        <td align="left" height="26"><font size="2">&nbsp;
        <a target="aa" href="TZ_Lckcp.htm">
        <span style="text-decoration: none">
        <font color="#000000">
        <img border="0" src="pic/table.gif" width="21" height="18">&nbsp;
        馏出口产品质量分析台账</font></span></a></font></td>
       </tr>
       <tr>
        <td align="left" height="27"><font size="2">&nbsp;
        <a target="aa" href="TZ_Sztz.htm">
        <span style="text-decoration: none">
        <font color="#000000">
        <img border="0" src="pic/table.gif" width="21" height="18">&nbsp;
        水质台账</font></span></a></font></td>
       </tr>
       <tr>
        <td align="left" height="31"><font size="2">&nbsp;
        <img border="0" src="pic/table.gif" width="21" height="18">&nbsp;
        <a target="aa" href="TZ_Hbtz.htm">
        <span style="text-decoration: none">
        <font color="#000000">环保台账</font></span></a></font></td>
       </tr>
   
       <tr>
        <td align="left">
        <p align="center"> </td>
       </tr>
       <tr>
        <td align="left" height="25">
      <p>
        <img border="0" src="pic/kingsoft.gif" width="19" height="21"><font size="2"><span style="text-decoration: none"><a target="_parent" id="back"><span style="text-decoration: none">返回上一级</span></a></span></font></p></td>
       </tr>
      </table>
     </td>
     <td align="center" width="72%" height="388" bordercolor="#003366" background="pic/800lims_main_tzcx2_c2.jpg">
     <iframe  name="aa" n  frameborder=no src="index.htm" width="635" height="387"></iframe>
        </td>
     <P></P>
     </TD>
     </tr>
    <tr>
     <td width="99%" colSpan="2" height="52" background="pic/800lims_main_r6_c1.jpg">
      </td>
    </tr>
    </table>
  </div>
 </body>
 <script language="javascript">
 <!--
 var back = document.getElementById("back");
 if (document.referrer.length == 0)
  back.href = "index.htm"
 else
  back.href = document.referrer;
 -->
 </script>

 
</html>

注意红色部分。需要说明的是:
1、首先判断document.referrer是否为空,如果为空,则页面访问是通过直接录入而来的,页面导向首页,否则导向引用页面。
2、代码需要放在页面后面,这样才能够访问到back连接元素。
3、需要在Web服务器上测试,在本地浏览时,无论何时referrer都为空。我也是多次试验才发现的。
补充:
刚看到一个帖子,很好。可以如下解决:
<a target="_parent" id="back"><span style="text-decoration: none">返回上一级</span></a>改为
<a target="_parent" id="back" href=javascript:history.back()><span style="text-decoration: none">返回上一级</span></a>
后来:发现它需要在C/S程序中调用HTM页面,通过IEBrowser控件,又通过Cookie方式进行了实现
基本原理是在包含这个连接的页面载入时,写入该页面连接到Cookie中,返回时读取写入的Cookie进行返回。
posted on 2007-10-24 14:32  bluesky7305  阅读(316)  评论(0编辑  收藏  举报