简体   繁体   English

我可以调整浏览器窗口的大小吗?

[英]Can I resize the browser window?

I want to resize a browser popup window's width and height. 我想调整浏览器弹出窗口的宽度和高度。 I can set the popup window size but I want to convert the window size fit to contents size when a page is redirected to another page. 我可以设置弹出窗口大小,但我想在将页面重定向到另一个页面时将窗口大小转换为适合内容大小。

I tried this: 我试过这个:

$(window).width(1000);  // Not working.

How can I do this? 我怎样才能做到这一点?

Update 更新

Everybody told me not to do it. 每个人都告诉我不要这样做。 To find out the exact reason why this is bad practice, I asked on ux.stackexchange.com . 为了找出这是不好的做法的确切原因,我在ux.stackexchange.com询问

I found some answers to this question. 我找到了这个问题的一些答案。 This question is duplicate. 这个问题是重复的。 But I'll answer again because I'll integrate them and add some more information. 但我会再次回答,因为我会整合它们并添加更多信息。

To resize the window, you can simply do this: 要调整窗口大小,您只需执行以下操作:

window.resizeTo(width, height);

But this method is not working in Chrome and Opera. 但是这种方法在Chrome和Opera中不起作用。 How do you resize an IE browser window to 1024 x 768 如何将IE浏览器窗口的大小调整为1024 x 768

The reason, from The javascript "resizeTo" function not working in Chrome and Opera , is: 原因是, javascript“resizeTo”功能在Chrome和Opera中不起作用 ,是:

The resizeTo method is disabled by default in several browsers, and I know that it can also be manually disabled in Firefox. 默认情况下,在几个浏览器中禁用resizeTo方法,我知道它也可以在Firefox中手动禁用。

It has been widely misused, so most browser vendors feel that it should be disabled, or at least a user controllable option. 它被广泛滥用,因此大多数浏览器供应商认为它应该被禁用,或者至少是用户可控制的选项。

But the method is working on popups even in Chrome or Opera. 但该方法即使在Chrome或Opera中也会处理弹出窗口。 I guess the reason is that the browser vendors thought the resizeTo method could be needed in popups, and I think so. 我想原因是浏览器供应商认为弹出窗口中可能需要resizeTo方法,我想是的。

To discuss this I made a thread about this issue on ux.stackexchange.com. 为了讨论这个问题,我在ux.stackexchange.com上就此问题提出了一个主题。 https://ux.stackexchange.com/questions/9903/why-is-resizing-the-browser-window-bad-practice/9962#9962 https://ux.stackexchange.com/questions/9903/why-is-resizing-the-browser-window-bad-practice/9962#9962

I'm not sure if the resizeTo method is evil in every case but I'm sure that one should be careful when using this method. 我不确定resizeTo方法在每种情况下都是邪恶的,但我确信在使用这种方法时应该小心。

使用

window.resizeBy(relativeW, relativeH);
<script type="text/javascript">
    function changeScreenSize() {        
        window.resizeTo(screen.width-300,screen.height-500)   
    }
</script>

<body onload="changeScreenSize()">

Whilst you might technically be able to do this, you really shouldn't. 虽然你可能在技术上可以做到这一点,但你真的不应该这样做。 forcing the size of the browser window fundamentally changes the browsing experience for a user which isn't your place to do. 强制浏览器窗口的大小从根本上改变了不适合您的用户的浏览体验。 Very bad practise and poor user experience. 非常差的做法和糟糕的用户体验。

Edit: Interesting to still get comments on this, but to be clear this answer is 6 years old, which is an age in web development time. 编辑:有 兴趣仍然对此有所评论,但要明确这个答案是6岁,这是一个Web开发时间的年龄。 Rather than edit it in context or delete it, I would say that it is wise to investigate current web development UX practises. 我会说,研究当前的 Web开发用户体验实践是明智的,而不是在上下文中进行编辑或删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM