禁用浏览器窗口调整大小 [英] Disable Browser Window Resize
问题描述
对于初学者......我没有任何恶意的意图让用户接受弹出窗口或类似的东西。我只是想阻止用户调整他们已经导航过的网页的浏览器窗口(意味着我无权访问/不想使用window.open();)。我已经研究了很长一段时间了,似乎找不到一个直截了当的答案。
For starters... I have no sinister intention of subjecting users to popups or anything like that. I simply want to prevent a user from resizing the browser window of a webpage to which they've already navigated (meaning I don't have access to / don't want to use window.open();). I've been researching this for quite a while and can't seem to find a straightforward answer.
我觉得我正在走上正轨:
I felt like I was on track with something along the lines of:
$(window).resize(function() {
var wWidth = window.width,
wHeight = window.height;
window.resizeBy(wWidth, wHeight);
});
......无济于事。我不得不想象这是可能的。是吗?如果是这样,我一定会感谢你的帮助。
...to no avail. I have to imagine this is possible. Is it? If so, I would definitely appreciate the help.
谢谢
推荐答案
您可以先确定一个确定的大小。
You can first determine a definite size.
var size = [window.width,window.height]; //public variable
然后执行此操作:
$(window).resize(function(){
window.resizeTo(size[0],size[1]);
});
演示: http://jsfiddle.net/DerekL/xeway917/
问:这不会导致无限循环的大小调整吗? - user1147171
不错的问题。这不会导致无限循环的大小调整。 W3C规范声明 resize
仅在调整文档视图大小时才调度事件。当 resizeTo
函数尝试第二次执行时,窗口将具有与刚设置完全相同的维度,因此浏览器不会触发resize事件,因为维度没有改变。
Nice question. This will not cause an infinite loop of resizing. The W3C specification states that resize
event must be dispatched only when a document view has been resized. When the resizeTo
function try to execute the second time, the window will have the exact same dimension as it just set, and thus the browser will not fire the resize event because the dimensions have not been changed.
这篇关于禁用浏览器窗口调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!