如何在单击注销按钮时关闭弹出窗口显示mvc视图

问题描述:

您正在使用以下代码打开MVC视图作为弹出窗口..



window.open(../ Employee / Report?Id =+ '<%=(string)Model.clsobj [0] .ID%>'+&Name =+'<%=(string)Model.clsobj [0] .Name%>','MyReport' ,'left = 250,top = 80,width = 800,height = 520,toolbar = 1,resizable = 0');



如果打开我必须关闭这个窗口点击退出按钮。(退出按钮在主页面上)请指导..

Hi am opening a MVC view as a popup using the below code..

window.open("../Employee/Report?Id=" + '<%= (string) Model.clsobj[0].ID %>' + "&Name=" + '<%= (string) Model.clsobj[0].Name %>' , 'MyReport', 'left=250,top=80,width=800,height=520,toolbar=1,resizable=0');

If opened i have to close this window on click of logout button.(logout button is on master page) Please guide ..

请参阅我对该问题的评论。首先,我强烈建议您检查您的UI设计并避免这些事情。问题甚至没有结束。更基本的问题是 window.open 。这被称为弹出窗口并且非常糟糕的声誉。它不仅对用户来说太过方便,而且许多用户使用弹出窗口阻止软件来对抗弹出窗口,最常见的是以浏览器插件的形式。你的整个窗口可能根本不显示。



在这个警告之后,我会给你正式答案,但在许多情况下它都不会起作用。这是食谱:

Please see my comment to the question. First of all, I would strongly advise to review your UI design and avoid such things. The problem is not even closing. More basic problem is window.open. This is called "popup" and has very bad reputation. Not only it is too intrusive to be convenient enough for the users, but many user fight against popups with popup blocking software, most typically in the form of browser plug-ins. Your whole window may not show up at all.

After this warning, I'll give you the formal answer, but it won't work in a number of cases. Here is the recipe:
var popup = window.open( //...

//...

popup.close();



此外, window.close()关闭当前窗口: https://developer.mozilla.org/en-US/docs/Web/API/Window/close [ ^ ]。



但是当前窗口方法在某些情况下可能不起作用。比如说,如果你的窗口实际上是一个标签,它将无法工作.JavaScript无法看到差异,但它不会起作用。基于从开始返回的方法应该有效。



我已经建议:不要做它一个合理的替代方案是所谓的模态弹出(这个名字令人困惑;事实上,这是在同一页面上模仿类似行为的一些模仿;但它解决了几乎所有问题)。有关更多详细信息,请阅读我的上一篇文章,其中我详细解释了所有内容,但是,他们提供了另一种实现:从零开始的模态弹出窗口 [ ^ ]。



但是你不必使用我的实现:有jQuery Dialog Widget和许多(真的很多)第三方插件和其他实现。 />


-SA


Also, window.close() closes current window: https://developer.mozilla.org/en-US/docs/Web/API/Window/close[^].

But the current-window approach may not work in some cases. Say, it won't work if your window is actually a tab. JavaScript cannot "see" the difference, but it won't just work. First approach based on the return from open should work.

I already suggested: don't do it. One reasonable alternative would be so called modal popup (this name is doubly confusing; in fact, this is some emulation of modal-like behavior on the same page; but it solves nearly all problems). For further detail, please read my last article, where I explain it all in detail, and, but they way, provide yet another implementation: Modal Popup From Scratch[^].

But you don't have to use my implementation: there is jQuery Dialog Widget and many (really many) 3rd-party plug-ins and other implementations.

—SA