0

我想打开一个弹出窗口并禁用父窗口。下面是我正在使用的代码。由于某种原因,父窗口没有被禁用。我是否需要一些额外的代码或者是什么情况?我还想在父页面被禁用时将其显示为灰色,所以也请帮助我。

<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>

4

1 回答 1

0

您可以创建一个具有灰色半透明背景的 div,将其绝对定位在父窗口的内容之上(使用 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);
于 2012-05-29T07:38:41.357 回答