Javascript弹出窗口。焦点
我有这个功能:Javascript弹出窗口。焦点,javascript,popup,Javascript,Popup,我有这个功能: var replyTo = null; var windWidth = 730; var windHeight = 550; var windTop = parseInt((screen.availHeight - windHeight) / 3); var windLeft = parseInt((screen.availWidth - windWidth) / 2); function windowPreOpen() { replyTo = windo
var replyTo = null;
var windWidth = 730;
var windHeight = 550;
var windTop = parseInt((screen.availHeight - windHeight) / 3);
var windLeft = parseInt((screen.availWidth - windWidth) / 2);
function windowPreOpen() {
replyTo = window.open('', 'Connect With Twitter', 'width=' + windWidth + ', height=' + windHeight + ', left=' + windLeft + ', top=' + windTop + ', scrollbars, resizable');
window.focus();
};
function makeReplyTo() {
windowPreOpen();
var user_id = "3";
var data = $.ajax({
type: "POST",
url: "uspolitics_pulse/functions.php",
data: {
type: 'checkOauth',
user_id: user_id
},
success: function (data) {
if (data) {
replyTo = window.open(data, 'Connect With Twitter', 'width=' + windWidth + ', height=' + windHeight + ', left=' + windLeft + ', top=' + windTop + ', scrollbars, resizable');
replyTo.focus();
} else {
replyTo.close()
replyTo = $.prettyPhoto.open('');
}
}
});
}
它包含一个小技巧,以避免弹出阻止阻止我的弹出窗口。
它首先打开一个空的弹出窗口,然后将其替换为正确的弹出窗口
问题是我必须将第一个弹出窗口隐藏在主窗口下,然后将焦点放在新窗口上
但是当我尝试使用replyTo.focus()时;弹出窗口仍然隐藏在主窗口后面,看起来我无法解决此问题
有没有办法重新聚焦弹出窗口
请看一下代码
谢谢为什么不简单地创建一个弹出窗口;不要隐藏它;并在XHR返回时更新其位置?例如:
var replyTo = null;
var windWidth = 730;
var windHeight = 550;
var windTop = parseInt((screen.availHeight - windHeight) / 3);
var windLeft = parseInt((screen.availWidth - windWidth) / 2);
function windowPreOpen() {
replyTo = window.open('', 'Connect With Twitter', 'width=' + windWidth + ', height=' + windHeight + ', left=' + windLeft + ', top=' + windTop + ', scrollbars, resizable');
window.focus();
};
function makeReplyTo() {
windowPreOpen();
var user_id = "3";
var data = $.ajax({
type: "POST",
url: "uspolitics_pulse/functions.php",
data: {
type: 'checkOauth',
user_id: user_id
},
success: function (data) {
if (data) {
replyTo.location = data;
} else {
replyTo.close();
replyTo = $.prettyPhoto.open('');
}
}
});
}
正是出于这种原因,我们通常避免使用真正的窗口/弹出窗口。我看到你在使用jQuery,所以你真的应该考虑只使用jQuery i对话框()。