2012-05-29 15 views
0

我想打開一個彈出窗口並禁用父窗口。下面是我使用的代碼。出於某種原因,父窗口不會被禁用。我是否需要一些額外的代碼或者情況如何?我也想在禁用時將父頁面變灰,所以請幫助我。父窗口未通過javascript在asp.net網頁中禁用

<script type="text/javascript"> 

    var popupWindow = null; 
    function OpenPopup() { 
     popupWindow = window.open("ClockPopUP.aspx", "Time", "scrollbars=no,resizable=no,width=550,height=350,left=300,top=300"); 
     return false; 
    } 

    function parent_disable() { 
     if (popupWindow && !popupWindow.closed) 
      popupWindow.focus(); 
      document.onmousedown = focusPopup; 
      document.onkeyup = focusPopup; 
      document.onmousemove = focusPopup; 
     } 
     function focusPopup() { 
      if (popupWindow && !popupWindow.closed) { popupWindow.focus(); } 
     } 
    function CheckDateEalier(sender, args) 
    { 
     var toDate = new Date(); 
     toDate.setMinutes(0); 
     toDate.setSeconds(0); 
     toDate.setHours(0); 
     toDate.setMilliseconds(0); 
     if (sender._selectedDate < toDate) 
     { 
      alert("You can't select day earlier than today! In Case if you are selecting Previous date then, By default it will take current Date."); 
      sender._selectedDate = toDate; 
      //set the date back to the current date 
      sender._textbox.set_Value(sender._selectedDate.format(sender._format)) 
     } 
     if (sender._selectedDate > toDate) 
     { 
      document.getElementById('<%= txtTimeSpent.ClientID%>').disabled = false; 
     } 
    } 

<asp:Content ID="Content1" ContentPlaceHolderID="cphTop" runat="server" > 
<asp:ScriptManager ID="ScriptManger1" runat="server"> 
     <%--<Scripts> 
      <asp:ScriptReference Path="js/Progress.js"/> 
     </Scripts>--%> 
    </asp:ScriptManager> 
<asp:UpdatePanel runat="server" ID="updProduction"> 
    <ContentTemplate> 
    <div id="counter" > 
    </div> 
    <div id="content"> 
    <div id="right"> 
    &nbsp 
     <asp:Button ID="Button1" runat="server" Text="Lunch" CausesValidation="false" CssClass="bigbuttons" style="background:url(../App_Themes/Images/green-box.gif)" Font-Bold="True" ForeColor="White" Font-Size="Large" /> <br /> 
     <asp:Button ID="Button2" runat="server" Text="Break" CausesValidation="false" CssClass="bigbuttons" style="background:url(../App_Themes/Images/red-box.gif)" Font-Bold="True" ForeColor="White" Font-Size="Large" /> <br /> 
     <asp:Button ID="Button3" runat="server" Text="L&amp;D Training " CausesValidation="false" CssClass="bigbuttons" style="background:url(../App_Themes/Images/green-box.gif)" Font-Bold="True" ForeColor="White" Font-Size="Large" /> <br /> 
     <asp:Button ID="Button4" runat="server" Text="Shift End" CausesValidation="false" CssClass="bigbuttons" style="background:url(../App_Themes/Images/red-box.gif)" Font-Bold="True" ForeColor="White" Font-Size="Large" /> <br /> 
    </div> 
</div> 

回答

0

您可以創建一個灰色半透明背景股利,你絕對定位在父窗口的內容(使用的z-index)。在這個div上,你可以綁定onclick事件來關注其他窗口。

事情是這樣的:

var disableDiv = document.createElement("div"); 
disableDiv.style.zIndex = 1000; 
disableDiv.style.position="absolute"; 
disableDiv.style.width = "1024px"; //adjust this to your spec 
disableDiv.style.height = "800px"; //adjust this to your spec 
disableDiv.style.background = "rgba(100,100,100, .5)"; 

if(document.attachEvent){ 
    disableDiv.attachEvent('onclick', function (e) { 
    //do IE stuff 
    }) 
}else{ 
    disableDiv.addEventListener("click", function (e) { 
    //do stuff 
    }, false); 
} 

document.body.appendChild(disableDiv);