【发布时间】:2017-07-08 20:11:27
【问题描述】:
我有一个点击后会打开的窗口。
function PopupManager() {
this.name = "_popupmanager_";
this.windows = {};
};
PopupManager.prototype.open = function(url, option, size, name) {
var url = "http://google.com"
var option = "null, status=no, toolbar=no, menubar=no, titlebar=no,
location=no, scrollbars=no, resizable=no"
var size = 'height=200, width = 814'
this.windows[name] = window.open(url, option, size, name);
this.windows[name].focus();
};
PopupManager.prototype.closeAll = function() {
for (name in this.windows) {
this.closeWindow(name);
}
}
PopupManager.prototype.closeWindow = function(name) {
if (this.windows[name]) {
if (!this.windows[name].closed) {
this.windows[name].opener.name="indexpage";
this.windows[name].close();
}
delete this.windows[name];
}
};
//初始化
document.getElementById("popupManager").onclick = function (e) {
e.preventDefault();
var popupManager = new PopupManager();
popupManager.open('http://www.google.com', 'google');
}
我认为这应该关闭同一个窗口。
document.getElementById("closeIt").onclick = function (e) {
e.preventDefault();
var popupManager = new PopupManager();
popupManager.closeAll();
popupManger.closeWindow();
}
没有控制台错误,也没有任何反应。就是不会关闭。
我试图使用相同的 标记来使用 if else 语句打开和关闭窗口,但我无法弄清楚。所以现在我正在尝试使用两个不同的 标签,(是的,我知道这很愚蠢)一个打开一个关闭,但我什至不能这样做。
我什至无法弄清楚我在这里做错了什么。
任何帮助将不胜感激。叹息……
【问题讨论】:
-
尝试打开同源窗口并告诉我结果
-
我打开同源窗口;我已经为这个问题在 google.com 中添加了这个问题,这样这个问题就不会因为过于具体到该位置或类似的东西而被关闭。
-
确定你关闭窗口在同一个脚本中打开它吗?还是从另一个脚本窗口本身?
-
当您执行
new PopupManager();时,您实例化了一个新实例,而this.windows不再是您认为的那样。 -
@Mouneer,我正在从同一个文档和同一个脚本打开和关闭窗口。不涉及单独的页面或脚本。
标签: javascript function onclick window