admin管理员组文章数量:1312996
I have seen many examples on using javascript to resize a browser window, but for me they all fail to perform that function in IE. I include my code to see if anything is wrong with it that I just don't see. The code works great in FF but that is not used at my location.
I am no javaScript expert, but I am no slouch either. If I were new to javaScript I would be hating it. I'm sure it has something to do with IE but I cannot explain it.
Any help would be great.
CODE:
//window.sizeToContent();
window.resizeTo(700, 700);
I read in the docs that sizeToContent will not work in IE but resize should. It is an incredibly simple statement.
I have seen many examples on using javascript to resize a browser window, but for me they all fail to perform that function in IE. I include my code to see if anything is wrong with it that I just don't see. The code works great in FF but that is not used at my location.
I am no javaScript expert, but I am no slouch either. If I were new to javaScript I would be hating it. I'm sure it has something to do with IE but I cannot explain it.
Any help would be great.
CODE:
//window.sizeToContent();
window.resizeTo(700, 700);
I read in the docs that sizeToContent will not work in IE but resize should. It is an incredibly simple statement.
Share Improve this question edited Oct 22, 2010 at 12:58 Pointy 414k62 gold badges594 silver badges627 bronze badges asked Oct 22, 2010 at 12:49 Travis CulbrethTravis Culbreth 861 silver badge5 bronze badges 6- 2 Check out the MSDN article about this method: msdn.microsoft./en-us/library/ms536723(VS.85).aspx – Šime Vidas Commented Oct 22, 2010 at 12:52
- 2 Many browsers have the option to not allow scripts to resize windows, because it's one of those features that have been abused. I'm not sure IE8 specifically has this option (or generally doesn't allow resizing), but it's something you should consider. – RoToRa Commented Oct 22, 2010 at 12:55
- 3 Please don't do that, it's a pain for visitors to have their window resized, especially when having multiple tabs opened... Although (in firefox at least) one can prevent it in the browser options – GôTô Commented Oct 22, 2010 at 12:56
- Thanks all for the responses. I just changed the initial window.open attributes to make the window the size I needed. Here is the issue I was trying to solve. 0) user clicks a button. 1) open new window (modal w/sizes) 2) load jsp 3) depending on the loaded rec. the page size is variable. 4) if 3 increase the window size. 5) all this occurred during initial load. @Šime - very true. I needed the onload resize. @Tim - Since the resize was wanted on the onload it would be unnoticed, hopefully @Francisco – As I have outlined I am doing just as you say Thank you all for your assistance. tnx IE – Travis Culbreth Commented Apr 25, 2011 at 13:54
- @GôTô - You are correct about resizing an existing window. I was looking for and answer for it not working. My window to be resized was a newly opened window. A small detail that would have releived your concern. – Travis Culbreth Commented Apr 25, 2011 at 13:58
5 Answers
Reset to default 2This works for me in Internet explorer 8
<html>
<head>
</head>
<body>
<h1>Resized</h1>
<script>
window.resizeTo(400,400);
</script>
</body>
I did some testing in IE9 beta (that's the only version of IE that I have on this machine), and it seems that window.resizeTo does not work on the initial page load. It does work if you refresh the page. Also, it does work if you delay its execution:
setTimeout(function() {
window.resizeTo(200, 200);
}, 2000);
(at least in IE9 beta)
The "working" example with IE is working only because there are no more tabs on the window.
If the windows has other tabs loaded, then it DOES NOT work. It's a security measure of IE8 and higher.
If you need to resize your window, you will need to open a new window. And for that, you will need to make the user click a button with the window.open onclick event, otherwise any popup blocker will block it.
You won't be able to resize the window reliably with JavaScript. It's not possible in IE 7 with tabbed browsing enabled. It's also potentially annoying for the user.
This seems to be IE only.
If your window is a "dialog" like:
window.showModalDialog(url,...)
I found this hacky way to make it the right size:
<script type="text/javascript">
//window.resizeTo(1000, 790); //Will not work if its a dialog
window.dialogWidth = '1000px';
window.dialogHeight = '790px';
</script>
本文标签: Using Javascript to resize browser window in IE8 Explanation mostlyStack Overflow
版权声明:本文标题:Using Javascript to resize browser window in IE8. Explanation mostly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741890261a2403260.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论