- var myPage;
- function openMyPage(){
- if (!myPage || myPage.closed){
- myPage=window.open("demo.html", "_blank");
- myPage.blur();
- }
- else{
- alert("new.htm is already opened.");
- }
- }
- //关闭上面打开的 IE 窗口
- function closeMyPage(){
- myPage.close();
- }
- //置前 IE 窗口
- function focusMyPage(){
- myPage.focus();
- }
- //置后 IE 窗口
- function blurMyPage(){
- myPage.blur();
- }
<input type="button" onClick="openMyPage();" VALUE="打开窗口">
点击“打开窗口”按钮后,如果 new.htm 没有打开,则打开它;如果打开了,就报告“new.htm is already opened.”。
原理就是把新打开的页面变成一个变量
上面的代码,还可以实现对新的IE窗口进行关闭、置前、置后操作。但是以上方法只能打开、判断、操作本 IE 内代码控制的窗口,对别的 IE 进程的子窗口不起作用。