开发者

Javascript resizing of Firefox pop-up window?

开发者 https://www.devze.com 2023-03-08 12:11 出处:网络
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 chec

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.

Usi开发者_StackOverflow社区ng 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?


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()});
});


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;

<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

精彩评论

暂无评论...
验证码 换一张
取 消