如何为弹出窗口设置焦点?

时间:2019-03-05 06:30:41

标签: c# html asp.net

在我的网页中,我打开了一个通知弹出窗口,其中包含一些消息。我需要打开该弹出窗口后,焦点应在该特定窗口中导航,而不是在主网站中。

我使用以下代码打开了弹出窗口

<div class="cd-popup">
        <div class="cd-popup-container">
            <asp:GridView runat="server"
                ID="gvNotificationsShow"
                                    AllowPaging="True"
                AutoGenerateColumns="False"
                                    GridLines="None"
                ShowHeader="true"
                class="tablemaster">
                <Columns>
                    <asp:TemplateField HeaderText="" ItemStyle-CssClass="Grid">
                        <HeaderTemplate><span class="headerGradient">Notifications list</span></HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblNotification" runat="server" Text='<%# Eval("NotificationText").ToString().Replace("\n","<br/>") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerStyle HorizontalAlign="Center" />
            </asp:GridView>

            <a href="#" id="notify" onclick="openMarkup()" class="cd-popup-close">
                <img src="../Lib/UI/img/noimage.png" class="transparent" alt="no image"></a>
        </div>
        <!-- cd-popup-container -->
    </div>

2 个答案:

答案 0 :(得分:0)

由于您尚未为openMarkup方法提供JavaScript,因此我假设您在该方法中有一个名为popupWindow的变量。然后,要将焦点移至弹出窗口,可以使用如下所示的JavaScript。

var popupWindow = window.open('xyz.aspx');//you could have more parameters passed to open method
if(window.focus) {
     popupWindow.focus();
}

答案 1 :(得分:0)

选中此项(需要Jquery)

$(document).on('keyup keypress', function (e) {
    var keyCode = e.keyCode || e.which;
    if (keyCode === 9) {
    if($('#popupelementid').is(':visible'))
     {
        e.preventDefault();
        return false;
     }
    }
});
相关问题