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

发布于 2024-11-29 12:50:22 字数 375 浏览 2 评论 0原文

我想调整浏览器弹出窗口的宽度和高度。我可以设置弹出窗口大小,但我想在页面重定向到另一个页面时将窗口大小转换为适合内容大小。

我尝试过:

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

我该怎么做?

更新

每个人都告诉我不要这样做。为了找出这是不好的做法的确切原因,我在 ux.stackexchange.com

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╰◇生如夏花灿烂 2024-12-06 12:50:22

我找到了这个问题的一些答案。这个问题是重复的。但我会再次回答,因为我将整合它们并添加更多信息。

要调整窗口大小,您可以简单地执行以下操作:

window.resizeTo(width, height);

但此方法在 Chrome 和 Opera 中不起作用。 如何调整 IE 浏览器窗口的大小到 1024 x 768

原因,来自 javascript“resizeTo”函数在 Chrome 和 Opera 中不起作用,是:

resizeTo 方法在一些浏览器中默认是禁用的,我
要知道,它也可以在 Firefox 中手动禁用。

它已被广泛滥用,因此大多数浏览器供应商认为它
应该被禁用,或者至少是一个用户可控的选项。

但即使在 Chrome 或 Opera 中,该方法也适用于弹出窗口。我猜原因是浏览器供应商认为弹出窗口中可能需要 resizeTo 方法,我也这么认为。

为了讨论这个问题,我在 ux.stackexchange.com 上发布了一个关于这个问题的帖子。
https://ux.stackexchange.com/ questions/9903/why-is-resizing-the-browser-window-bad-practice/9962#9962

我不确定是否resizeTo 方法在任何情况下都是邪恶的,但我确信使用此方法时应该小心。

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. How do you resize an IE browser window to 1024 x 768

The reason, from The javascript "resizeTo" function not working in Chrome and Opera, is:

The resizeTo method is disabled by default in several browsers, and I
know that it can also be manually disabled in 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. I guess the reason is that the browser vendors thought the resizeTo method could be needed in popups, and I think so.

To discuss this I made a thread about this issue on ux.stackexchange.com.
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.

嘿咻 2024-12-06 12:50:22
<script type="text/javascript">
    function changeScreenSize() {        
        window.resizeTo(screen.width-300,screen.height-500)   
    }
</script>

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

<body onload="changeScreenSize()">
葬﹪忆之殇 2024-12-06 12:50:22

使用

window.resizeBy(relativeW, relativeH);

use

window.resizeBy(relativeW, relativeH);
童话里做英雄 2024-12-06 12:50:22

虽然从技术上讲您可能能够做到这一点,但实际上您不应该这样做。强制浏览器窗口的大小从根本上改变了用户的浏览体验,这不是你该做的。非常糟糕的做法和糟糕的用户体验。

编辑:对此问题的评论仍然很有趣,但要明确的是,这个答案已经有 6 岁了,这是网络开发时代的一个年龄。我想说的是,调查当前网络开发用户体验实践是明智的,而不是在上下文中编辑它或删除它。

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. Rather than edit it in context or delete it, I would say that it is wise to investigate current web development UX practises.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文