onclick 打开窗口和特定大小

IT技术 javascript html
2021-01-29 14:11:55

我有一个这样的链接:

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')

我希望新的打开窗口以特定大小打开。如何指定高度和宽度?

6个回答
<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11"
   onclick="window.open(this.href,'targetWindow',
                                   `toolbar=no,
                                    location=no,
                                    status=no,
                                    menubar=no,
                                    scrollbars=yes,
                                    resizable=yes,
                                    width=SomeSize,
                                    height=SomeSize`);
 return false;">Popup link</a>

其中宽度和高度是没有单位的像素(宽度=400 不是宽度=400px)。

在大多数浏览器中,如果它不是在没有换行符的情况下编写的,它将无法工作,一旦设置了变量,所有内容都在一行中:

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=SomeSize,height=SomeSize'); return false;">Popup link</a> 
@IdhamChoudry 只需删除宽度/高度属性,它就会自动占用所有可用空间。我相信设置width=100vw, height=100vh也会起作用。
2021-03-17 14:11:55
一个旧的,但我通过搜索找到了这个,所以根据@AndrewSpear 的回复更正了答案
2021-03-19 14:11:55
您还需要将最后一个 ")" 字符替换为 ");return false;" 以防止在弹出窗口之外打开原始链接。
2021-03-31 14:11:55
对我来说它有效,但一件重要的事情 - 你不应该在你的函数体中使用换行符,如上例所示。我已经删除了换行符,它对我有用。
2021-04-02 14:11:55
@Larry Hipp 我怎样才能改变它以适应屏幕的大小?
2021-04-04 14:11:55
window.open ("http://www.javascript-coder.com",
"mywindow","menubar=1,resizable=1,width=350,height=250");

http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

:]

window.open('http://somelocation.com','mywin','width=500,height=500');

只需将它们添加到参数字符串中即可。

window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250')
<a style="cursor:pointer"
  onclick=" window.open('http://YOUR.URL.TARGET','',' scrollbars=yes,menubar=no,width=500, resizable=yes,toolbar=no,location=no,status=no')">Your text</a>
虽然我确实问,这对所有已经给出的答案有什么补充?
2021-04-04 14:11:55