在javascript中的Window.close()

编程入门 行业动态 更新时间:2024-10-25 02:25:11
本文介绍了在javascript中的Window.close()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个usercontrol,我想打开一个错误窗口来显示错误消息。我在ascx.cs中使用了window.open,窗口打开正确。 现在我想通过调用另一个方法来关闭打开的窗口,我在使用window.close()。 这对我不起作用。请帮帮我。 注意:当我使用IE调试器进行调试时,显示'ErrorWindow'未定义 我尝试过: 公共覆盖无效ErrorMessage() { string url = string.Empty; ClientScriptManager cs = Page.ClientScript; url =ErrorEnhanced.aspx; 输入cstype = this.GetType(); string script = string.Empty; script =var ErrorWindow = window.open('+ url +', 'ErrorWindow','width = 400,height = 200,left = 550,top = 180,resizable = no,location = no,toolbars = 0,scrollbars = 0,statusbars = 0,menubar = 0')。focus() ;; cs.RegisterStartupScript(cstype,Error_Script,脚本,true); } public override void CloseErrorWindow() { ClientScriptManager cs = Page.ClientScr ipt; 类型cstype = this.GetType(); string script = string.Empty; script =var ErrorWindow; if(ErrorWindow!= null){; script + =ErrorWindow.close();}; cs.RegisterStartupScript(cstype,Error_Script,script ,true); }

解决方案

你不能关闭用户服务器的窗口。 用java脚本关闭它。使用javascript返回(部分)视图。 只需在这里调用window.close()。

function openWin(){ myWindow = window.open(,myWindow,width = 200,height = 100); //打开一个新窗口} 函数closeWin(){ myWindow.close(); //关闭新窗口}

I have a usercontrol where i want to open a error window to display error messages. I have used the window.open in ascx.cs, the window opened correctly. Now i want to close the opened window by calling another method where i am using window.close(). It is not working for me. Please help me on this. Note: when i debugged using IE debugger, It shows 'ErrorWindow' undefined What I have tried: public override void ErrorMessage() { string url = string.Empty; ClientScriptManager cs = Page.ClientScript; url = "ErrorEnhanced.aspx"; Type cstype = this.GetType(); string script = string.Empty; script = "var ErrorWindow = window.open('" + url + "', 'ErrorWindow', 'width=400,height=200,left=550,top=180,resizable=no, location=no,toolbars=0,scrollbars=0,statusbars=0,menubar=0').focus();"; cs.RegisterStartupScript(cstype, "Error_Script", script, true); } public override void CloseErrorWindow() { ClientScriptManager cs = Page.ClientScript; Type cstype = this.GetType(); string script = string.Empty; script = "var ErrorWindow; if(ErrorWindow != null){"; script += "ErrorWindow.close();}"; cs.RegisterStartupScript(cstype, "Error_Script", script, true); }

解决方案

You can't close the window of a user server sided. Close this with java-script. Return a (partial)view with a javascript. Just call window.close() here.

function openWin() { myWindow = window.open("", "myWindow", "width=200, height=100"); // Opens a new window } function closeWin() { myWindow.close(); // Closes the new window }

更多推荐

在javascript中的Window.close()

本文发布于:2023-11-09 15:35:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:javascript   Window   close

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!