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

jquery - Javascript resizing of Firefox pop-up window? - Stack Overflow

programmeradmin0浏览0评论

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('/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?

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?

Share Improve this question edited May 26, 2011 at 11:42 Holland asked May 25, 2011 at 12:23 HollandHolland 4224 silver badges10 bronze badges 4
  • 1 You can't be assured that any browser will let you control the size of windows you create. You can't even be sure you'll get a window at all - people can instruct their browsers to open all new windows as browser tabs. – Pointy Commented May 25, 2011 at 12:49
  • Agreed - sorry, I wasn't clear. I need Firefox to open to nearly the dimension requested in Javascript without having to ask the user to adjust his internal about:config settings – Holland Commented May 26, 2011 at 11:43
  • You were quite clear and Pointy is right: If the user has the "window resize" option turned off, then it's impossible to change the window size. – RoToRa Commented May 26, 2011 at 15:05
  • Yep - thought as much. Thanks Pointy & RoToRa – Holland Commented May 27, 2011 at 8:39
Add a ment  | 

4 Answers 4

Reset to default 1

I would highly remend 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()});
});

Firefox es 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;

<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.

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

发布评论

评论列表(0)

  1. 暂无评论