日期:2014-05-18  浏览次数:20366 次

请教各位:关于打开新窗体和关闭窗体的问题(超难)
1.点击一个可以打开新窗体的链接,如何实现如果窗体已打开,则将焦点转到已打开的窗体,否则打开新窗体。难点:如何判断窗体已打开,及将将打开的窗体Active?

2.如何实现一个主窗体关闭时,将所有   打开的其他相关窗体一起关闭?


我们主管以前是做WinForm的,现在升级系统Asp.net做开发。但思维模式还是WinForm。提的这两个要求实难下手去做,请教各位是否有办法实现,若有请告之,谢谢!

------解决方案--------------------
沙发~
------解决方案--------------------
是得变,感觉这些事情在asp.net都是 “不可能 "事件
------解决方案--------------------
mark
------解决方案--------------------
尽量不要在webform中打开新的ie窗口,太多的插件可能拦截
开新窗口可以在原来窗口里改变一个标志量,使用该标志量作标示判断是否有新窗口打开
无法做到讲ie窗口关联关闭,但是可以使用模式窗口,让焦点保持在子窗口,当子窗口关闭才能关闭父窗口
------解决方案--------------------
偶认为这两个在Web普通应用中几乎不太可能实现,如果你不是打开一个窗口而是一个新的div,然后判断div是否存在的话应该可以实现Active。
------解决方案--------------------
虽然是有点变态,还硬是将他基本实现了,希望不会有太多潜在bug~

其实自己很早都有这种需求,只是之前都懒得去尝试,变样实现了,

现在有点崇拜那句话了, "nothing is impossible! ",当然前提是要合理的^_^

欢迎拍砖~


// p.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head>
<title> Parent window </title>
<script type= "text/javascript ">
function openWin() {
//debugger;
var url = sltWins.value;
var winName = url.replace( '. ', '_ ');
var win;
win = winMap[winName];
try {
win.focus();
}catch(e) {
// alert(e.message);
// we need to open a new window when the child window has not
// been opened or the child window has been close.
// as to the later, you also can implements some method that notices the parent window
// to remove the child window from our winMap object when it is closing.
// but it 's a piece of hard work, i think so, because you must
// add the notice codes to all the child windows
//
win = window.open(url, winName, "top=100,left=100,width=400,height=300 ");
winMap[winName] = win;
//
if(!win) {
alert( "Sorry, fail to open the window.Some unexpected error occurs. ");
}
else {
// i try to bind a callback function to the child window 's unload event
// unfortunately, it seems not to work.
// win.onunload = function() {
// try {
// alert(opener.winMap[winName]);
// opener.winMap[winName] = null;
// alert(opener.winMap[winName]);
// } catch(e) {
// // alert(e.message);
// }
// };
win.focus();
}
}
}
</script>
<script type= "text/javascript ">
// stores the opened window object
var winMap = new Object();
//winMap[ "TestedKey "] = "TestedValue ";
window.onunload = function() {
// try to close all child windows.
for(var propName in winMap) {