我希望将焦点保持在新的弹出窗口中并禁止用户单击父窗口,除非关闭弹出窗口。每次点击链接时,我的代码都会关注弹出窗口。我想在每次打开时都把注意力集中在弹出窗口上。
以下是我的HTML代码。
function PopupCenter(url, title, w, h) {
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
}
<a href="" class="btn btn-outline btn-info btn-xs" onClick="PopupCenter('transfer.php?id=<?php echo $putIn;?>','xtf','980','350');">Transfer</a>
答案 0 :(得分:0)
您可以通过以下方式实现focus
function popitup(url) {
newwindow = window.open(url, 'name', 'height=200,width=150');
if (window.focus) {
newwindow.focus()
}
if (!newwindow.closed) {
newwindow.focus()
}
return false;
}
编辑: 如果上述方法不起作用,那么另一种方法是从父窗口中删除焦点
<html>
<head>
<script type="text/javascript">
var popupWindow=null;
function child_open()
{
popupWindow =window.open('new.jsp',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");
}
function parent_disable() {
if(popupWindow && !popupWindow.closed)
popupWindow.focus();
}
</script>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
<a href="javascript:child_open()">Click me</a>
</body>
</html>