通过javascript出现弹出窗口时,父窗口未禁用. [英] Parent window not disabling when pop up appears via javascript.

查看:94
本文介绍了通过javascript出现弹出窗口时,父窗口未禁用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开一个弹出窗口并禁用父窗口.下面是我正在使用的代码.由于某种原因,父窗口不会被禁用.我在父级中使用母版页并添加onClientClick事件以在父级页加载时打开弹出窗口.我是否需要一些其他代码,或者是什么情况?

I want to open a popup window and disable the parent window. Below is the code that I am using.For some reason, the parent window does not get disabled. I m using master page in my parent and adding onClientClick event to open pop up at page load of Parent page.Do I need some additional code OR what is the case?

<pre lang="Javascript">
<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;
            }
        }
</script>



Aspx父页面:



Aspx Parent Page:

<asp:Content ID="Content1" ContentPlaceHolderID="cphTop" runat="server" >
    <asp:ScriptManager ID="ScriptManger1" runat="server">
        </asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="updProduction">
        <ContentTemplate>
        <div id="counter" >
        </div>
        <div id="content">
        <div id="right">
         

            <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&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 id="formload" >
		    <!-- ============================== Fieldset 1 ============================== -->
		    <fieldset>
			    <legend>Enter Date</legend>
                <label for="input-one" class="float">Date</label><br />                        
                            <asp:TextBox ID="txtDate" runat="server" CssClass="inp-text" Enabled="False" 

                                Width="300px"></asp:TextBox>  
                            <asp:Image ID="btnDate2" runat="server" AlternateText="cal2" 

                                ImageUrl="~/App_Themes/Images/icon_calendar.jpg" />
                            <ajaxToolkit:CalendarExtender ID="calExtender2"  runat="server" 

                                Format="dddd, MMMM dd, yyyy" OnClientDateSelectionChanged="CheckDateEalier" 

                                PopupButtonID="btnDate2" TargetControlID="txtDate" />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 

                                ControlToValidate="txtDate" ErrorMessage="Select a Date" Font-Bold="True" 

                                Font-Size="X-Small" ForeColor="Red"></asp:RequiredFieldValidator><br />
                            <br />
		    </fieldset>
		    <!-- ============================== Fieldset 1 end ============================== -->


		    <!-- ============================== Fieldset 2 ============================== -->
		    <fieldset>
			    <legend>Production Detail</legend>
                <label for="input-one" class ="float"> Time Spent In minutes</label><br />
                 <asp:TextBox ID="txtTimeSpent" runat="server"  Width="300px" style="display:inherit;" CssClass="inp-text" Enabled="false"></asp:TextBox>
                  <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="TimeSpent will be numeric and non decimal" ControlToValidate="txtTimeSpent" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ValidationExpression="^\d+$" Width="400px"></asp:RegularExpressionValidator>
				

				    <label for="input-one" class="float">Nature of Work </label><br />
                    <asp:DropDownList ID="ddlNatureofWork" runat="server" CssClass="inp-text" 

                    Width="300px" onselectedindexchanged="ddlNatureofWork_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                    <asp:RequiredFieldValidator id="RequiredFieldValidator1"  runat="server" ErrorMessage="Please make a selection"  ControlToValidate="ddlNatureofWork"  InitialValue="--Select Nature of Work--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br />

                    <label for="input-one" class="float">Region/Project Name </label><br />

				    <asp:DropDownList ID="ddlRegionProjectName" runat="server" 

                    CssClass="inp-text" Width="300px" 

                    onselectedindexchanged="ddlRegionProjectName_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
                    <asp:RequiredFieldValidator id="RequiredFieldValidator2"  runat="server" Display="Dynamic" ErrorMessage="Please make a selection"  ControlToValidate="ddlRegionProjectName"  InitialValue="--Select Region/Project--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br />


                    <label for="input-one" class="float">County Name</label><br />

				    <asp:DropDownList ID="ddlCountyName" runat="server" CssClass="inp-text" 

                    Width="300px" AutoPostBack="true" 

                    onselectedindexchanged="ddlCountyName_SelectedIndexChanged"></asp:DropDownList>
                     <asp:RequiredFieldValidator id="RequiredFieldValidator3"  runat="server" ErrorMessage="Please make a selection"  ControlToValidate="ddlCountyName"  InitialValue="--Select County--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br />

                

                    

                    <label for="input-one" class="float">WorkType</label><br />
				    <asp:DropDownList ID="ddlWorkType" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true"   onselectedindexchanged="ddlWorkType_SelectedIndexChanged"></asp:DropDownList>
                     <asp:RequiredFieldValidator id="RequiredFieldValidator4"  runat="server" ErrorMessage="Please make a selection"  ControlToValidate="ddlWorkType"  InitialValue="--Select WorkType--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br />


                    <label for="input-one" class="float">Task </label><br />

				    <asp:DropDownList ID="ddlTask" runat="server" CssClass="inp-text" 

                    Width="300px" AutoPostBack="true" 

                    onselectedindexchanged="ddlTask_SelectedIndexChanged"></asp:DropDownList>
                    <asp:RequiredFieldValidator id="RequiredFieldValidator5"  runat="server" ErrorMessage="Please make a selection"  ControlToValidate="ddlTask"  InitialValue="--Select Task--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br />

		    </fieldset>
		    <!-- ============================== Fieldset 2 end ============================== -->


		    <!-- ============================== Fieldset 3 ============================== -->
		    <fieldset>
			    <legend>Completed Volumes</legend>
			        <label for="input-one" class="float">Volume Processed </label><br />
                    <asp:TextBox ID="txtVolumeProcessed" runat="server" CssClass="inp-text" Width="300px"></asp:TextBox>
                    <asp:RequiredFieldValidator id="RequiredFieldValidator6"  runat="server" ErrorMessage="Please enter the volume processed"  ControlToValidate="txtVolumeProcessed"   Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Volume must be numeric and non decimal" ControlToValidate="txtVolumeProcessed" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ValidationExpression="^\d+$" Width="400px"></asp:RegularExpressionValidator>
				
		    </fieldset>
		    <!-- ============================== Fieldset 3 end ============================== -->

		    <p><asp:ImageButton ID="ImgBtnSubmit" runat="server" ImageUrl="~/App_Themes/Images/form_submit.gif" onclick="ImgBtnSubmit_Click" /></p>
            <p>
                <asp:Label ID="lblConfirmation" runat="server" Text="Label" CssClass="labelError" Visible="false"></asp:Label> </p>
	    </div>
        </div>
        
            <div id="gridview">
                <asp:GridView ID="GVUserEnteredDetails" runat="server" BackColor="White" 

                    BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="15">
                    <FooterStyle BackColor="White" ForeColor="#000066" />
                    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                    <RowStyle ForeColor="#000066" />
                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#007DBB" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#00547E" />
                </asp:GridView>
            </div>
            
        </ContentTemplate>
    </asp:UpdatePanel>
    <div class="divTextAlign">
                <asp:Updateprogress id="updProgress" runat="server" dynamiclayout="true" associatedupdatepanelid="updProduction">
                    <Progresstemplate>
                        <img src="App_Themes/Images/ajax-loader.gif" alt="" />
                    </Progresstemplate>
            </asp:Updateprogress> 
    </div>
</asp:Content>

推荐答案

" Width="400px"></asp:RegularExpressionValidator> <label for="input-one" class="float">Nature of Work </label><br /> <asp:DropDownList ID="ddlNatureofWork" runat="server" CssClass="inp-text" Width="300px" onselectedindexchanged="ddlNatureofWork_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlNatureofWork" InitialValue="--Select Nature of Work--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">Region/Project Name </label><br /> <asp:DropDownList ID="ddlRegionProjectName" runat="server" CssClass="inp-text" Width="300px" onselectedindexchanged="ddlRegionProjectName_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" Display="Dynamic" ErrorMessage="Please make a selection" ControlToValidate="ddlRegionProjectName" InitialValue="--Select Region/Project--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">County Name</label><br /> <asp:DropDownList ID="ddlCountyName" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true" onselectedindexchanged="ddlCountyName_SelectedIndexChanged"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlCountyName" InitialValue="--Select County--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">WorkType</label><br /> <asp:DropDownList ID="ddlWorkType" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true" onselectedindexchanged="ddlWorkType_SelectedIndexChanged"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator4" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlWorkType" InitialValue="--Select WorkType--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">Task </label><br /> <asp:DropDownList ID="ddlTask" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true" onselectedindexchanged="ddlTask_SelectedIndexChanged"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator5" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlTask" InitialValue="--Select Task--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> < /fieldset > <!-- ============================== Fieldset 2 end ============================== --> <!-- ============================== Fieldset 3 ============================== --> < 字段集 > <legend>Completed Volumes</legend> <label for="input-one" class="float">Volume Processed </label><br /> <asp:TextBox ID="txtVolumeProcessed" runat="server" CssClass="inp-text" Width="300px"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator6" runat="server" ErrorMessage="Please enter the volume processed" ControlToValidate="txtVolumeProcessed" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Volume must be numeric and non decimal" ControlToValidate="txtVolumeProcessed" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ValidationExpression="^\d+
" Width="400px"></asp:RegularExpressionValidator> <label for="input-one" class="float">Nature of Work </label><br /> <asp:DropDownList ID="ddlNatureofWork" runat="server" CssClass="inp-text" Width="300px" onselectedindexchanged="ddlNatureofWork_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlNatureofWork" InitialValue="--Select Nature of Work--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">Region/Project Name </label><br /> <asp:DropDownList ID="ddlRegionProjectName" runat="server" CssClass="inp-text" Width="300px" onselectedindexchanged="ddlRegionProjectName_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" Display="Dynamic" ErrorMessage="Please make a selection" ControlToValidate="ddlRegionProjectName" InitialValue="--Select Region/Project--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">County Name</label><br /> <asp:DropDownList ID="ddlCountyName" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true" onselectedindexchanged="ddlCountyName_SelectedIndexChanged"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator3" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlCountyName" InitialValue="--Select County--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">WorkType</label><br /> <asp:DropDownList ID="ddlWorkType" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true" onselectedindexchanged="ddlWorkType_SelectedIndexChanged"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator4" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlWorkType" InitialValue="--Select WorkType--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <label for="input-one" class="float">Task </label><br /> <asp:DropDownList ID="ddlTask" runat="server" CssClass="inp-text" Width="300px" AutoPostBack="true" onselectedindexchanged="ddlTask_SelectedIndexChanged"></asp:DropDownList> <asp:RequiredFieldValidator id="RequiredFieldValidator5" runat="server" ErrorMessage="Please make a selection" ControlToValidate="ddlTask" InitialValue="--Select Task--" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> </fieldset> <!-- ============================== Fieldset 2 end ============================== --> <!-- ============================== Fieldset 3 ============================== --> <fieldset> <legend>Completed Volumes</legend> <label for="input-one" class="float">Volume Processed </label><br /> <asp:TextBox ID="txtVolumeProcessed" runat="server" CssClass="inp-text" Width="300px"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator6" runat="server" ErrorMessage="Please enter the volume processed" ControlToValidate="txtVolumeProcessed" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ></asp:RequiredFieldValidator><br /> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Volume must be numeric and non decimal" ControlToValidate="txtVolumeProcessed" Font-Bold="True" Font-Size="X-Small" ForeColor="Red" ValidationExpression="^\d+


" Width="400px"></asp:RegularExpressionValidator> < /fieldset > <!-- ============================== Fieldset 3 end ============================== --> <p><asp:ImageButton ID="ImgBtnSubmit" runat="server" ImageUrl="~/App_Themes/Images/form_submit.gif" onclick="ImgBtnSubmit_Click" /></p> < p > <asp:Label ID="lblConfirmation" runat="server" Text="Label" CssClass="labelError" Visible="false"></asp:Label> </p> < /div > < /div > <div id="gridview"> <asp:GridView ID="GVUserEnteredDetails" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="15"> < FooterStyle =" 白色" ForeColor >#000066" / > < HeaderStyle =" #006699" 字体粗体 True" ForeColor =" 白色" / > < PagerStyle =" 白色" ForeColor >#000066" Horizo​​ntalAlign =" 左侧" / < RowStyle =" #000066" / < SelectedRowStyle =" #669999" 字体粗体 True" ForeColor =" 白色" / > < SortedAscendingCellStyle =" #F1F1F1" / <SortedAscendingHeaderStyle BackColor="#007DBB" /> < SortedDescendingCellStyle =" #CAC9C9" / <SortedDescendingHeaderStyle BackColor="#00547E" /> < /asp:GridView > < /div > < /ContentTemplate > < /asp:UpdatePanel > <div class="divTextAlign"> <asp:Updateprogress id="updProgress" runat="server" dynamiclayout="true" associatedupdatepanelid="updProduction"> <Progresstemplate> <img src="App_Themes/Images/ajax-loader.gif" alt="" /> </Progresstemplate> </asp:Updateprogress> < /div > </asp:Content>
" Width="400px"></asp:RegularExpressionValidator> </fieldset> <!-- ============================== Fieldset 3 end ============================== --> <p><asp:ImageButton ID="ImgBtnSubmit" runat="server" ImageUrl="~/App_Themes/Images/form_submit.gif" onclick="ImgBtnSubmit_Click" /></p> <p> <asp:Label ID="lblConfirmation" runat="server" Text="Label" CssClass="labelError" Visible="false"></asp:Label> </p> </div> </div> <div id="gridview"> <asp:GridView ID="GVUserEnteredDetails" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="15"> <FooterStyle BackColor="White" ForeColor="#000066" /> <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> <RowStyle ForeColor="#000066" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#007DBB" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#00547E" /> </asp:GridView> </div> </ContentTemplate> </asp:UpdatePanel> <div class="divTextAlign"> <asp:Updateprogress id="updProgress" runat="server" dynamiclayout="true" associatedupdatepanelid="updProduction"> <Progresstemplate> <img src="App_Themes/Images/ajax-loader.gif" alt="" /> </Progresstemplate> </asp:Updateprogress> </div> </asp:Content>


you should use showModalDialog function of js
so that you can''t work with parent window ..

例如

you should use showModalDialog function of js
so that you can''t work with parent window ..

e.g.

window.showModalDialog("chieldpage.html","chield","dialogWidth:300px;dialogHeight:300px");


这篇关于通过javascript出现弹出窗口时,父窗口未禁用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆