javascript (window.open) 在所有浏览器中打开最大化,但不是在 chrome 中打开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25795934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 21:52:50  来源:igfitidea点击:

javascript (window.open) opens maximized in all browsers but not in chrome

javascriptjqueryhtmlgoogle-chromepopup

提问by Alaa

I am using the following code to open a maximized pop up window, i don't want to open it full screen (F11), I need it just maximized, exactly like pressing the button between minimize and close.

我正在使用以下代码打开一个最大化的弹出窗口,我不想全屏打开它(F11),我只需要最大化它,就像在最小化和关闭之间按下按钮一样。

<a  onclick="javascript:w= window.open('https://www.facebook.com/mywifemylove','_blank','channelmode =1,scrollbars=1,status=0,titlebar=0,toolbar=0,resizable=1');" href="javascript:void(0);" target="_blank">Maximized on Chrome</a>

It's working fine for all browsers but not Chrome, Here is a jsfiddlefor testing

它适用于所有浏览器但不适用于 Chrome,这是一个用于测试的jsfiddle

回答by DanielST

With the exception of IE, browsers do not support going fullscreen with JS. This is intentional:

除 IE 外,浏览器不支持使用 JS 全屏显示。这是故意的:

https://developer.mozilla.org/en-US/docs/Web/API/window.open#FAQ

https://developer.mozilla.org/en-US/docs/Web/API/window.open#FAQ

"All browser manufacturers try to make the opening of new secondary windows noticed by users and noticeable by users to avoid confusion, to avoid disorienting users."

“所有浏览器制造商都试图让用户注意到并引起用户注意的新辅助窗口的打开,以避免混淆,避免使用户迷失方向。”

You can manually set the size of the window to the screen size but you may have to deal with things like frame border thickness.

您可以手动将窗口大小设置为屏幕大小,但您可能需要处理诸如边框粗细之类的问题。

Relevant SO question: How to open maximized window with Javascript?

相关SO问题: 如何使用Javascript打开最大化窗口?

Working code for max size window on latest versions of IE, FF or Chrome:

最新版本的 IE、FF 或 Chrome 上最大尺寸窗口的工作代码:

window.open('http://www.stackoverflow.com','_blank','height='+screen.height+', width='+screen.width);

回答by Bojana Cubranovic

function openMax() { 
var wihe = 'width='+screen.availWidth+',height='+screen.availHeight; 
window.open("ht*p://www.example.com/", 
"foo", 
"screenX=1,screenY=1,left=1,top=1," + wihe); 
}

回答by Varma

I think following code is helpful to you.

我认为以下代码对您有帮助。

<a  id="popupLink" href="#"> link name</a> 
       jquery.click(function(e){
       e.preventDefault();
       var newTab =window.open('','_blank','channelmode=1,scrollbars=1,status=0,titlebar=0,toolbar=0,resizable=1');
        newTab.location = "https://www.facebook.com/mywifemylove";
        newTab.focus();
});

回答by Bunty Kumar

You can open window tab with below code:-

您可以使用以下代码打开窗口选项卡:-

window.open(src, "newWin", "width="+screen.availWidth+",height="+screen.availHeight)