Javascript 调整 Firefox 弹出窗口的大小?
我正在学习 Javascript 和 jQuery,但我是一个 HTML'r,试图采取下一步..
我试图将内容放入表格中,该表格可以是任何大小(这是一个新闻网站) 。我检查大小,然后相应地调整弹出窗口的大小;虽然窗口不完全正确,但它可以工作,但在 Firefox 中它甚至无法调整大小。
使用通用链接弹出一个基本窗口:
<a onclick="window.open('http://site.local/popup/','popup','width=1,height=1')">popup</a>
我将其指向默认页面,cms 将所有内容放入表格中(id="top")。它有一个默认的 width="1" 来强制约束,然后让内容扩展表格以设置实际大小。然后,我检查表大小以查看 document.ready() 上的窗口并调整其大小:
<script type="text/javascript">
<!--
$(document).ready(function() {
var divh = document.getElementById('top').offsetHeight;
var divw = document.getElementById('top').offsetWidth;
//Test size
//alert("Table: width= " + divw + "px / height= " + divh +"px");
//Resize
window.resizeTo(divw,divh);
}
-->
</script>
我需要能够调整已在 Firefox 中打开的窗口的大小。
所有窗口大小(Firefox 除外)均已关闭,但我可以填充它们 - 稍大一点比截断更好。不幸的是,Firefox 生成了一个 180w x 249h 的小窗口,并且从不调整大小。
我在这里搜索不成功 - 大多数人建议在 Firefox 中编辑设置,我显然不能指望用户这样做。
有什么想法吗?
I'm just learning Javascript and jQuery, but I'm an HTML'r trying to take the next step..
I'm attempting to drop content into a table, which can be any size at all (It's for a news site). I check for size and then resize the popup accordingly; while the window isn't exactly right it works, but in Firefox it's not even resizing.
Using a generic link to pop-open a basic window:
<a onclick="window.open('http://site.local/popup/','popup','width=1,height=1')">popup</a>
I'm pointing it to a default page where the cms is placing all content into a table (id="top"). It has a default width="1" to force a constraint, and then letting the content expand the table to set the real size. I then check the table size to see and resize the window on document.ready():
<script type="text/javascript">
<!--
$(document).ready(function() {
var divh = document.getElementById('top').offsetHeight;
var divw = document.getElementById('top').offsetWidth;
//Test size
//alert("Table: width= " + divw + "px / height= " + divh +"px");
//Resize
window.resizeTo(divw,divh);
}
-->
</script>
I need to be able to resize a window already opened in Firefox.
All the window sizes (except Firefox) are off but I can pad them - a little larger is better than cut-off. Firefox, unfortunately, generates a tiny 180w x 249h window and never resizes.
I've searched here unsuccessfully - most suggest editing a setting in firefox, which I clearly can't expect users to do.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我强烈建议您用 div 弹出窗口替换您的弹出窗口。您将遇到像 Firefox 一样的问题,并且浏览器完全阻止它。假设您已包含 jqueryui 并且您正在从同一域加载此内容:
I would highly recommend replacing your popup with a div popup. You're going to run into issues like you have with Firefox, and browsers blocking it altogether. Assuming you have jqueryui included and you're loading this content from the same domain:
Firefox 为用户提供了允许/禁止使用 Javascript 调整窗口大小的偏好。它在工具-选项-内容-启用Javascript-> [先进的]。
我不确定默认情况下是否禁用调整大小,但您可能需要首先检查您自己的 Firefox 安装。
如果默认情况下禁用它,那么不幸的是,在打开窗口后您无法调整窗口大小。一个丑陋的解决方法是使用具有首选大小的
window.open()
再次打开自身。Firefox comes with a preference for user to allow/disallow resizing of window using Javascript. It's in Tools - Options - Content - Enable Javascript -> [Advanced].
I am not sure if resizing is disabled by default, but you might want to check your own Firefox installation first.
If it's disabled by default, then unfortunately there is nothing you could do to resize the window after it has been opened. An ugly workaround would be to open itself once again using
window.open()
with the preferred size though.尝试这样的事情;
这样您就不需要调整窗口大小,而只需最初设置大小即可。
Try something like this;
That way you shouldn't need to resize the window, but just set the size initially.
为什么不通过ajax请求获取内容并将其显示在当前内容上方的div中?
Why not getting the content with ajax request and display it in a div above the current content?