js 代码
- 下面的表格列出了 window 对象某些属性的相关信息。
- 属性 方法 描述
- opener open opener 属性仅在使用 window.open 方法打开的页面中可用。
- parent, top 无 parent 和 top 属性对 frame 或 iframe 内打开的窗口可用。这两个属性分别返回立即父窗口和最上层的祖先窗口。
- parent, top open parent 和 top 属性对于通过 open 方法打开或以对话框打开并返回到当前窗口的窗口可用。
- length 无 不管窗口是怎么打开的,length 属性总是返回窗口中的框架数目。
- dialogArguments, dialogHeight, dialogLeft, dialogTop, dialogWidth, returnValue showModalDialog 和 showModelessDialog
- parent 获取对象层次中的父窗口。
- top 获取最顶层的祖先窗口。
- ****************************************************************
- 1、直接从框架页中退出,并转向到新的窗口
- if (Session["admin"] == null)
- {
- Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");
- Response.Write("<script language=javascript>top.location.href='../news/manager/login.aspx'</script>");
- }
- 2、如果需要在框架页中关闭当前窗口并打开新窗口
- 1)先提示关闭当前窗口,并且在确定关闭当前窗口后,打开新窗口.
- if (Session["admin"] == null)
- {
- Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");
- Response.Write("<script>window.parent.close(); window.open('../news/manager/login.aspx');</script>");
- }
- 同样的效果:
- if (Session["admin"] == null)
- {
- Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");
- Response.Write("<script>window.opener=null;top.window.close();</script>");
- }
- 3、在框架中关闭当前窗口,不提示。并且打开新窗口
- if (Session["admin"] == null)
- {
- Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");
- Response.Write("<script>window.open('../news/manager/login.aspx');top.close();</script>");
- }
- if (Session["admin"] == null)
- {
- Response.Write("<script language=javascript>alert('登陆超时,请重新登陆!!')</script>");
- Response.Write("<script language=javascript>parent.location.href='../airquery/Admin-manager/index.asp'</script>");
- Response.Write("<script language=javascript>window.open('../airquery/Admin-manager/index.asp');opener=null;top.close();</script>");
- }
- window属性:
- opener 设置或获取创建当前窗口的窗口的引用。
- self 获取对当前窗口或框架的引用。
- windown方法:
- close 关闭当前浏览器窗口或 HTML 应用程序(HTA)。
- open 打开新窗口并装入给定 URL 的文档。
- 简单总结一下:
- 两句任意选一句都可完成表面上类似同样的效果。
- 但是实际效果上的差别:
- Response.Write("<script language=javascript>parent.location.href='../airquery/Admin-manager/index.asp'</script>");
- 这里将parent换成top也可以,没仔细研究为什么。自己使用。我在我的框架里top,left.right(三个框架的right使用无任何问题)
- 这个是直接转向到新页面,但是地址栏上的后退仍然是可以后退的,虽然点后退会在次返回,可是如我上面的写法,在page_load里,会再次提示“登陆超时,请重新登陆”确定后再返回。这样的效果,我不是很满意,所以得出了下面的使用方法。
- Response.Write("<script language=javascript>window.open('../airquery/Admin-manager/index.asp');opener=null;top.close();</script>");
- 这个的功能是什么实际效果呢?很简单,打开新窗口后,接下来,将原来的框架窗口关闭,注意是新窗口,那么当然后退按钮就变成灰色的了。客户端自然无法后退了。这个效果我比较喜欢。很符合我的原意(比如:不用考虑重复提交之类的问题了)。
- 另外我加上opener=null这句,是根据我的理解加上去的,好象去掉也照样可以实现同样的效果。这里如果将top换parent也同样可以使用。但是如果换window.close()那提示框又回来了。以上都是在IE6.0以上版本实现的效果,别的浏览器没试验过。
- 小注:我在查看文章的时候,有人这样说,在需要关闭的窗口<body>里加上οnblur="self.close()",然后在用window.close()方法关闭当前窗口也不会出现提示,但是我在我机器上怎么试都不行!不得而知为什么!
- 另外又有人说,如果是用open()方法打开的子窗口里,直接用windown.close()或top.close()都可以直接关闭窗口,我试了,好象这样的情况下,在body加上οnblur="self.close()"后,的确是可以的,但是不加的没测试。实现我的效果了。做个简单的记录。
- 查看window对象帮助发现一window方法
- returnValue 设置或获取从模式对话框返回的值。
- setInterval 每经过指定毫秒值后计算一个表达式。
- Evaluates an expression each time a specified number of milliseconds has elapsed.
- Syntax
- iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])
- Parameters
- vCode Required. Variant that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.
- iMilliSeconds Required. Integer that specifies the number of milliseconds.
- sLanguage Optional. String that specifies any one of the possible values for the LANGUAGE attribute.
- Return Value
- Integer. Returns an identifier that cancels the timer with the clearInterval method.
- Remarks
- The setInterval method continuously evaluates the specified expression until the timer is removed with the clearInterval method.
- 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.
- As of Internet Explorer 5, the first argument of setInterval can be passed as a string or as a function pointer.
- To pass a function as a string, be sure to suffix the function name with parentheses.
- window.setInterval("someFunction()", 5000);
- When passing a function pointer, do not include the parentheses.
- window.setInterval(someFunction, 5000);
- To retrieve a function pointer, use the code shown in the following example:
- function callback()
- {
- alert("callback");
- }
- function callback2()
- {
- alert("callback2");
- }
- function chooseCallback(iChoice)
- {
- switch (iChoice)
- {
- case 0:
- return callback;
- case 1:
- return callback2;
- default:
- return "";
- }
- }
- // if i is 0, callback is invoked after 5 seconds
- // if i is 1, callback2 is invoked
- // otherwise, the timer is not set
- window.setInterval(chooseCallback(i), 5000);
- 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.
- Example
- 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.
- var oInterval = "";
- function fnStartInterval(){
- oInterval = window.setInterval("fnRecycle()",1000);
- }
- function fnRecycle(){
- // Code to display hours, minutes, and seconds.
- }