Window.resizeBy() - Web APIs 编辑

The Window.resizeBy() method resizes the current window by a specified amount.

Syntax

window.resizeBy(xDelta, yDelta)

Parameters

  • xDelta is the number of pixels to grow the window horizontally.
  • yDelta is the number of pixels to grow the window vertically.

Example

// Shrink the window
window.resizeBy(-200, -200);

Notes

This method resizes the window relative to its current size. To resize the window in absolute terms, use window.resizeTo().

Creating and resizing an external window

For security reasons, it's no longer possible in Firefox for a website to change the default size of a window in a browser if the window wasn’t created by window.open(), or contains more than one tab. See the compatability table for details on the change.

Even if you create window by window.open() it is not resizable by default. To make the window resizable, you must open it with the "resizable" feature.

// Create resizable window
myExternalWindow = window.open("http://myurl.domain", "myWindowName", "resizable");

// Resize window to 500x500
myExternalWindow.resizeTo(500, 500);

// Make window relatively smaller to 400x400
myExternalWindow.resizeBy(-100, -100);

The window you create must respect the Same Origin Policy. If the window you open is not in the same orgin as the current window, you will not be able to resize, or access any information on, that window/tab.

Specifications

SpecificationStatusComment
CSS Object Model (CSSOM) View Module
The definition of 'window.resizeBy()' in that specification.
Working Draft 

Browser compatibility

BCD tables only load in the browser

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:49 次

字数:3066

最后编辑:6 年前

编辑次数:0 次

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