繁体   English   中英

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

[英]how to set focus for the pop-up window?

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

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

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

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

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

检查此(需要jQuery)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM