最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can a browser tab's scripts forcefully resize its window? - Stack Overflow

programmeradmin0浏览0评论

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 User Experience Stack Exchange.

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 User Experience Stack Exchange.

Share Improve this question edited Feb 1 at 15:46 Philippe Cloutier 5994 silver badges15 bronze badges asked Aug 11, 2011 at 8:15 Sanghyun LeeSanghyun Lee 23k19 gold badges105 silver badges126 bronze badges 10
  • 1 What do you mean by "When a page is moved to another page"? – Shadow Wizard Commented Aug 11, 2011 at 8:17
  • 4 Stop trying to annoy people. Thanks. – ThiefMaster Commented Aug 11, 2011 at 8:25
  • @ThiefMaster Not trying to annoy people. I just hope a website cant resize my browser because it is very annoying to the end user. – Michael Koper Commented Aug 11, 2011 at 8:29
  • @Shadow It means "When the URL of page is changed". Could you tell me how to describe this? – Sanghyun Lee Commented Aug 11, 2011 at 9:18
  • 1 For most browsers you can do that only for a window you've created, I've addressed this issue here: stackoverflow.com/questions/5139323/… – jave.web Commented Dec 26, 2016 at 19:14
 |  Show 5 more comments

4 Answers 4

Reset to default 54

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.

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

<body onload="changeScreenSize()">

use

window.resizeBy(relativeW, relativeH);

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.

发布评论

评论列表(0)

  1. 暂无评论