Javascript 调整 Firefox 弹出窗口的大小?

发布于 2024-11-09 12:09:19 字数 1020 浏览 0 评论 0原文

我正在学习 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

白馒头 2024-11-16 12:09:19

我强烈建议您用 div 弹出窗口替换您的弹出窗口。您将遇到像 Firefox 一样的问题,并且浏览器完全阻止它。假设您已包含 jqueryui 并且您正在从同一域加载此内容:

$('#container').load('/popup',function() {
     var table = $('#container #top');
    $('#container').dialog({height:table.height(), width: table.width()});
});

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:

$('#container').load('/popup',function() {
     var table = $('#container #top');
    $('#container').dialog({height:table.height(), width: table.width()});
});
别忘他 2024-11-16 12:09:19

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.

逆流 2024-11-16 12:09:19

尝试这样的事情;

<a class='poptrigger'>pop</a>

$(function(){
 var w = $("#top").outerWidth();
 var h = $("#top").outerHeight();
 $('.poptrigger').click(function{
  window.open('http://site.local/popup/','popup','width='+w+',height='+h)
 })
});

这样您就不需要调整窗口大小,而只需最初设置大小即可。

Try something like this;

<a class='poptrigger'>pop</a>

$(function(){
 var w = $("#top").outerWidth();
 var h = $("#top").outerHeight();
 $('.poptrigger').click(function{
  window.open('http://site.local/popup/','popup','width='+w+',height='+h)
 })
});

That way you shouldn't need to resize the window, but just set the size initially.

薆情海 2024-11-16 12:09:19

为什么不通过ajax请求获取内容并将其显示在当前内容上方的div中?

Why not getting the content with ajax request and display it in a div above the current content?

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