如何用Javascript打开最大化的窗口? [英] How to open maximized window with Javascript?
问题描述
我正在使用 Javascript 的 self.open()
在新窗口中打开一个链接,我希望该窗口最大化.我尝试了 fullscreen=yes
选项,这确实不符合我的要求.我正在使用以下代码:
I'm using Javascript's self.open()
to open a link in a new window and i'd like that window to be maximized. I tried the fullscreen=yes
option, which really doesn't do what I want. I am using below code:
self.open(pageLoc,popUpName,'height=1600,width=1800,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
如果我还提到 fullscreen=yes
,那么窗口会像按 F11 一样打开.但我不想那样.我想要的是当我双击 IE 并单击右上角的最大化图标.
If i also mention fullscreen=yes
, then window opens up like you press F11. But i don't want it that. What i want is when i double click on IE and click maximize icon on top right corner.
因为我给的 height
和 width
值太大了,它接近最大化窗口但不是实际最大化窗口.(我之所以这么说是因为即使现在我点击最大化按钮,它也会进一步扩展一点)
As i have given the height
and width
value so large, it is close to maximized window but not actual maximized window. (the reason i am saying this because
even now if i click maximize button, it further expans little bit)
推荐答案
var params = [
'height='+screen.height,
'width='+screen.width,
'fullscreen=yes' // only works in IE, but here for completeness
].join(',');
// and any other options from
// https://developer.mozilla.org/en/DOM/window.open
var popup = window.open('http://www.google.com', 'popup_window', params);
popup.moveTo(0,0);
除非用户真的想要,否则请不要打开弹出窗口,否则他们会诅咒您并将您的网站列入黑名单.;-)
Please refrain from opening the popup unless the user really wants it, otherwise they will curse you and blacklist your site. ;-)
编辑:糟糕,正如 Joren Van Severen 在评论中指出的那样,这可能没有考虑到任务栏和窗口装饰(以可能依赖于浏览器的方式).意识到.似乎忽略高度和宽度(只有参数是 fullscreen=yes
)似乎适用于 Chrome,也许也适用于 Firefox;最初的全屏"功能在 Firefox 中因令人讨厌而被禁用,但已被最大化取代.这直接与 https://developer.mozilla.org/en/DOM/window.open 同一页面上的信息相矛盾 表示窗口最大化是不可能的.取决于浏览器,此功能"可能受支持,也可能不受支持.
edit: Oops, as Joren Van Severen points out in a comment, this may not take into account taskbars and window decorations (in a possibly browser-dependent way). Be aware. It seems that ignoring height and width (only param is fullscreen=yes
) seems to work on Chrome and perhaps Firefox too; the original 'fullscreen' functionality has been disabled in Firefox for being obnoxious, but has been replaced with maximization. This directly contradicts information on the same page of https://developer.mozilla.org/en/DOM/window.open which says that window-maximizing is impossible. This 'feature' may or may not be supported depending on the browser.
这篇关于如何用Javascript打开最大化的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!