使用javascript打开子窗口时禁用父窗口

时间:2013-02-15 05:01:00

标签: javascript

  • 我有一个名为worklist.jsp的父窗口
  • 父窗口有一个按钮。单击该按钮,它将调用名为getEventLogUser()的函数。
  • getEventLogUser()函数依次调用名为popupWindowWithPost()的函数来打开子窗口。这个函数都在单独的js文件(utility.js)..
  • 我的需要是,我必须在打开孩子时禁用父窗口。

worklist.jsp:

<div class="claro" id="menuDiv21" onclick="setWidgetproperty(this.id,'x','navMenu21');" onmousedown="setMenuBarProperty('navMenu21');" onmouseup="setDocStyle(this.id)" style="border:1px dotted white; left: auto; position: absolute; top: 620px;">
     <div dojotype="dijit.MenuBar" id="navMenu21" style="font-size:11pt;" title="MenuBar">
          <div dojotype="dijit.MenuBarItem" id="SearchMenu21" onclick="getEventLogUser();setMenuId(this.id);" style="font-size:11pt;" title="menuBarItem">
               <img class="images" id="SearchMenu21" name="search5.png" onclick="setImgProperty(this.id)" src="images/uploads/search.png" style="height:20px; width:20px;">
               Search
          </div>
</div>
</div>

utility.js:

function getEventLogUser(){
        var dummyvar = document.getElementById("CWPROCESSEVENTLOG.OBJECT_ID").value;
        popupWindowWithPost("eventLogUser.jsp",'height=600px,width=960px,top=50px,left=150px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no','processManager',dummyvar);
}
function popupWindowWithPost(url, windowoption, name, params)
{
         var form = document.createElement("form");
         form.setAttribute("method", "post");
         form.setAttribute("action", url);
         form.setAttribute("target", name);
         var input = document.createElement('input');
         input.type = 'hidden';
         input.name = "PARAM";
         input.value = params;
         form.appendChild(input);
         document.body.appendChild(form);
         window.open(url, name, windowoption);
         form.submit();
         document.body.removeChild(form);
}

3 个答案:

答案 0 :(得分:2)

禁用窗口的一种简单方法(假设你的禁用定义与我上面的评论相匹配)就是简单地用不可见的div覆盖窗口并给它一个非常大的z-index,这样如果你有任何其他的dom元素z-index&gt; 1它仍将由那个看不见的div覆盖..

尝试避免像window.showModalDialog()这样的东西他们是bad news ..如果我是你...我甚至不会创建一个新窗口,除非它是绝对必要的(我想不出一个方案老实说)..我只是在同一个窗口中使用div和css创建一个模态对话框..在线有大量的教程和库(即twitter bootstrap)。

答案 1 :(得分:0)

据我所知,你想打开模态对话框。查看window.showModalDialog()而不是window.open()。注意,它也有一些不同的参数......

而且,如果你想把它放在form.submit();之前,那么在模态窗口关闭之前它不会被执行。

答案 2 :(得分:0)

查看fancybox库以创建模态iframe。我在一些项目中使用了它,它可以满足您的要求;虽然是叠加而不是在单独的窗口中。