http://stackoverflow.com/questions/29788754/open-multiple-child-windows-with-one-click
^^我刚收到一些小网站的帮助,现在我有了不同的想法。
http://alexalmaguer.site90.com/
每当我点击其中一个按钮时,最多会出现5个子窗口,并且它们都显示在屏幕中央,因为下面的脚本告诉他们这样做。当只有一个窗口打开时,这很好,但现在它们都出现在彼此的顶部。有什么方法可以改变这个以使窗口出现在随机位置吗?
function wopen(url, name, w, h)
{
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
if (wleft < 0) {
w = screen.width;
wleft = 0;
}
if (wtop < 0) {
h = screen.height;
wtop = 0;
}
var win = window.open(url, name,
'width=' + w + ', height=' + h + ', ' +
'left=' + wleft + ', top=' + wtop + ', ' +
'location=no, menubar=no, ' +
'status=no, toolbar=no, scrollbars=no, resizable=no');
win.resizeTo(w, h);
win.moveTo(wleft, wtop);
win.focus();
}
答案 0 :(得分:1)
function wopen(url, name, w, h) {
w += 32;
h += 96;
wleft = (screen.width - w) / 2;
wtop = (screen.height - h) / 2;
if (wleft < 0) {
w = screen.width;
wleft = 0;
}
if (wtop < 0) {
h = screen.height;
wtop = 0;
}
if (wleft > 0) {
wleft = Math.floor(Math.random() * wleft); // for example
}
var win = window.open(url, name,
'width=' + w + ',height=' + ',left=' + wleft + ',top=' + wtop);
win.focus();
}
替代方法是不随机,但要记住坐标并每次添加窗口宽度
另一种方法是打开左侧和顶部与鼠标点击坐标对齐的窗口