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