[英]how to set focus for the pop-up window?
In my web page I have opened a notification pop-up window which contains some message. 在我的网页中,我打开了一个通知弹出窗口,其中包含一些消息。 My need is after opening that pop-up the focus should navigate in that particular window not in the main web. 我需要打开该弹出窗口后,焦点应在该特定窗口中导航,而不是在主网站中。
I used the below codes to open 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>
Since you haven't provided your JavaScript for openMarkup
method, I will assume that you have a variable called popupWindow
in that method. 由于您尚未为openMarkup
方法提供JavaScript, openMarkup
我假设您在该方法中有一个名为popupWindow
的变量。 Then, to move focus to the popup window, you could use JavaScript as below. 然后,要将焦点移至弹出窗口,可以使用如下的JavaScript。
var popupWindow = window.open('xyz.aspx');//you could have more parameters passed to open method
if(window.focus) {
popupWindow.focus();
}
Check this(requires Jquery) 检查此(需要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.