分享

怎么在框架窗口中退出

 名字真麻烦 2010-04-19
  1. 下面的表格列出了 window 对象某些属性的相关信息。    
  2. 属性 方法 描述    
  3. opener open opener 属性仅在使用 window.open 方法打开的页面中可用。    
  4. parent, top 无 parent 和 top 属性对 frame 或 iframe 内打开的窗口可用。这两个属性分别返回立即父窗口和最上层的祖先窗口。    
  5. parent, top open parent 和 top 属性对于通过 open 方法打开或以对话框打开并返回到当前窗口的窗口可用。    
  6. length 无 不管窗口是怎么打开的,length 属性总是返回窗口中的框架数目。    
  7. dialogArguments, dialogHeight, dialogLeft, dialogTop, dialogWidth, returnValue showModalDialog 和 showModelessDialog    
  8.   
  9.   
  10. parent 获取对象层次中的父窗口。    
  11.   
  12. top 获取最顶层的祖先窗口。    
  13.   
  14. ****************************************************************   
  15.  1、直接从框架页中退出,并转向到新的窗口   
  16. if (Session["admin"] == null)   
  17.         {   
  18.             Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");   
  19.             Response.Write("<script language=javascript>top.location.href='../news/manager/login.aspx'</script>");   
  20.         }   
  21.   
  22. 2、如果需要在框架页中关闭当前窗口并打开新窗口   
  23. 1)先提示关闭当前窗口,并且在确定关闭当前窗口后,打开新窗口.   
  24. if (Session["admin"] == null)   
  25.         {   
  26.             Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");   
  27.             Response.Write("<script>window.parent.close(); window.open('../news/manager/login.aspx');</script>");           
  28.        }   
  29. 同样的效果:   
  30. if (Session["admin"] == null)   
  31.         {   
  32.             Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");   
  33.             Response.Write("<script>window.opener=null;top.window.close();</script>");   
  34.        }   
  35. 3、在框架中关闭当前窗口,不提示。并且打开新窗口   
  36. if (Session["admin"] == null)   
  37.         {   
  38.             Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");   
  39.             Response.Write("<script>window.open('../news/manager/login.aspx');top.close();</script>");          
  40.          }   
  41.   
  42.   
  43.         if (Session["admin"] == null)   
  44.         {   
  45.             Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");   
  46.             Response.Write("<script language=javascript>parent.location.href='../airquery/Admin-manager/index.asp'</script>");   
  47.   
  48.             Response.Write("<script language=javascript>window.open('../airquery/Admin-manager/index.asp');opener=null;top.close();</script>");   
  49.         }   
  50.   
  51.   
  52. window属性:   
  53.   
  54. opener 设置或获取创建当前窗口的窗口的引用。    
  55. self 获取对当前窗口或框架的引用。    
  56.   
  57. windown方法:   
  58.   
  59. close 关闭当前浏览器窗口或 HTML 应用程序(HTA)。    
  60. open 打开新窗口并装入给定 URL 的文档。    
  61.   
  62. 简单总结一下:   
  63.   
  64. 两句任意选一句都可完成表面上类似同样的效果。   
  65. 但是实际效果上的差别:   
  66. Response.Write("<script language=javascript>parent.location.href='../airquery/Admin-manager/index.asp'</script>");   
  67. 这里将parent换成top也可以,没仔细研究为什么。自己使用。我在我的框架里top,left.right(三个框架的right使用无任何问题)   
  68. 这个是直接转向到新页面,但是地址栏上的后退仍然是可以后退的,虽然点后退会在次返回,可是如我上面的写法,在page_load里,会再次提示“登陆超时,请重新登陆”确定后再返回。这样的效果,我不是很满意,所以得出了下面的使用方法。   
  69. Response.Write("<script language=javascript>window.open('../airquery/Admin-manager/index.asp');opener=null;top.close();</script>");   
  70. 这个的功能是什么实际效果呢?很简单,打开新窗口后,接下来,将原来的框架窗口关闭,注意是新窗口,那么当然后退按钮就变成灰色的了。客户端自然无法后退了。这个效果我比较喜欢。很符合我的原意(比如:不用考虑重复提交之类的问题了)。   
  71. 另外我加上opener=null这句,是根据我的理解加上去的,好象去掉也照样可以实现同样的效果。这里如果将top换parent也同样可以使用。但是如果换window.close()那提示框又回来了。以上都是在IE6.0以上版本实现的效果,别的浏览器没试验过。   
  72.   
  73. 小注:我在查看文章的时候,有人这样说,在需要关闭的窗口<body>里加上onblur="self.close()",然后在用window.close()方法关闭当前窗口也不会出现提示,但是我在我机器上怎么试都不行!不得而知为什么!   
  74. 另外又有人说,如果是用open()方法打开的子窗口里,直接用windown.close()或top.close()都可以直接关闭窗口,我试了,好象这样的情况下,在body加上onblur="self.close()"后,的确是可以的,但是不加的没测试。实现我的效果了。做个简单的记录。   
  75.   
  76.   
  77. 查看window对象帮助发现一window方法   
  78.   
  79. returnValue 设置或获取从模式对话框返回的值。    
  80. setInterval 每经过指定毫秒值后计算一个表达式。    
  81.   
  82.   
  83. Evaluates an expression each time a specified number of milliseconds has elapsed.   
  84.   
  85. Syntax   
  86.   
  87. iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])   
  88. Parameters   
  89.   
  90. vCode Required. Variant that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.    
  91. iMilliSeconds Required. Integer that specifies the number of milliseconds.    
  92. sLanguage Optional. String that specifies any one of the possible values for the LANGUAGE attribute.    
  93.   
  94. Return Value   
  95.   
  96. Integer. Returns an identifier that cancels the timer with the clearInterval method.    
  97.   
  98. Remarks   
  99.   
  100. The setInterval method continuously evaluates the specified expression until the timer is removed with the clearInterval method.    
  101.   
  102. In versions earlier than Microsoft? Internet Explorer 5, the first argument of setInterval must be a string. Evaluation of the string is deferred until the specified interval elapses.   
  103.   
  104. As of Internet Explorer 5, the first argument of setInterval can be passed as a string or as a function pointer.   
  105.   
  106. To pass a function as a string, be sure to suffix the function name with parentheses.   
  107.   
  108. window.setInterval("someFunction()", 5000);   
  109.   
  110. When passing a function pointer, do not include the parentheses.    
  111.   
  112. window.setInterval(someFunction, 5000);   
  113.   
  114. To retrieve a function pointer, use the code shown in the following example:   
  115.   
  116. function callback()   
  117. {   
  118. alert("callback");   
  119. }   
  120. function callback2()   
  121. {   
  122. alert("callback2");   
  123. }   
  124. function chooseCallback(iChoice)   
  125. {   
  126. switch (iChoice)   
  127. {   
  128. case 0:   
  129. return callback;   
  130. case 1:   
  131. return callback2;   
  132. default:   
  133. return "";   
  134. }   
  135. }   
  136. // if i is 0, callback is invoked after 5 seconds   
  137. // if i is 1, callback2 is invoked   
  138. // otherwise, the timer is not set   
  139. window.setInterval(chooseCallback(i), 5000);   
  140.   
  141.   
  142. When you use the setInterval method with Introduction to DHTML Behaviors, the value of vCode should be a function pointer to call a function within the HTML Component (HTC) file or a string to call a function in the primary document.    
  143.   
  144. Example   
  145.   
  146. This example uses the setInterval method to create a Dynamic HTML (DHTML) clock. A variable is assigned to the interval, and can be used as a reference to stop the interval using the clearInterval method.   
  147.   
  148. var oInterval = "";   
  149. function fnStartInterval(){   
  150. oInterval = window.setInterval("fnRecycle()",1000);   
  151. }   
  152. function fnRecycle(){   
  153. // Code to display hours, minutes, and seconds.   
  154. }   

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多