Email conversation
From | Pascal Niklaus |
To | Me |
Subject | Javascript |
Date | 18 September 2003 22:28 |
Hi !
I enjoyed your javascript site. There's however a problem I try solving which
might be worth looking at on your page: I'd like to resize a popup-window so
that it exactly fits the size of the content.
What I do now is set the (inner) window width to a certain amount, determine the
height of the content, and then set the height of the window. Now, the content
should fit exactly... However, I haven't come up with a solution that works on
all browsers (fails on Konqueror, for example).
Do you have any solution for this?
Thanks
Pascal
From | Me |
To | Pascal Niklaus |
Subject | Re: Javascript |
Date | 19 September 2003 09:04 |
Attachment | page which I modified to become my 'perfect popups' page |
Trying to find the height of the body is possible, but there are so many
browser differences, it becomes an almost impossible task to work around
all of them.
What I would do instead is:
put the entire body's contents into a DIV element,
position it absolutely at 0px, 0px to avoid margin issues and allow
browsers to treat it as a layer,
set its width to the desired width, and check the offsetHeight/clip.height
of the DIV, not the body.
This will work in all good browsers (including Netscape 4).
To resize the inner width to the size you want, and get it right in all
browsers, you need to resize it to a nominal size, check what size the
browser made the inside, then resize the outside again, adding on the
difference between inner and outer. The problem is that, except in some
Netscape 4 versions, resizeTo resizes the OUTSIDE, not the inside, so the
size of menus/window frames needs to be taken into account. As not all
browsers provide a way to calculate these, you need to do it this way.
Note, when opening the popup, set the 'resizable' option.
This is too complex to show in an email so I have attached a script to do
it for you. I have put comments in the source so that you can understand
what I am doing. Remove them if you want.
Tarquin - author of http://www.howtocreate.co.uk/
From | Me |
To | Pascal Niklaus |
Subject | Re: Javascript |
Date | 19 September 2003 13:39 |
As you requested, I have written a page to describe how to do this. I have
also added in how to open a popup and dynamically write its contents using
JavaScript before resizing it to fit the contents, because a number of
people have asked me how to do this as well.
http://www.howtocreate.co.uk/perfectPopups.html
From | Pascal Niklaus |
To | Me |
Subject | Re: Javascript |
Date | 19 September 2003 13:53 |
Wow! That was fast! You're site is really great. Javascript in itself is
already not the great language, but with all these browser dialects and
versions and compatibility modes it takes so much time to test and work
around all the bugs. Such solutions as on your site help a lot!
BTW, how do you test your scripts? I have a couple of browsers installed
(Konqueror, Mozilla, old Netscape 4 under Linux and Opera and IE6 under
MS Windows), but can't find a way to install IE4... I hoped to get it
running under Wine/linux, but failed. I'd hate to have to install a
separate partition just to boot Windows/IE4. Maybe you have a solution
for that as well?
Pascal
From | Me |
To | Pascal Niklaus |
Subject | Re: Javascript |
Date | 19 September 2003 14:15 |
> BTW, how do you test your scripts? I have a couple of browsers installed
> (Konqueror, Mozilla, old Netscape 4 under Linux and Opera and IE6 under
> MS Windows), but can't find a way to install IE4...
I use:
Clue, IE6, ICE, Opera 5/6/7, Mozilla 1.4.1, Netscape 4.0.2, Escape 4.8,
MSNTV viewer 2.8, HotJava, Linx, Lynx, Amaya on Windows XP (Work machine)
IE5, IE4.5, Opera 6, OmniWeb 4.2 and 4.5, iCab 2.9.5, Safari 1, Mozilla
1.4.1 on Mac OS X (Work Machine)
Konqueror 3.0, Opera 7, Lynx on RedHat Linux 7.3 (Work machine)
IE5, Opera 6 on Windows NT (Work machine)
Mozilla 1.4.1, Opera 7, Konqueror 2.1.1, Lynx on RedHat 7.2 (Home machine)
IE4/5.5, ICE, Opera 5/6/7, Mozilla 0.9.2/1.3, Netscape 4.0.2/6/7, Escape
4.8, WebTV viewer 2.6, HotJava, Linx, Lynx, Amaya on Windows 98 (Home
machine)
Too many computers, too many browsers :) but then, I have 5 computers at
work (and my job is in email, not web development ...), and two at home.
Your problem with IE4 is a common one. IE4 is only used by about 0.3% of
internet users, so if you can't install it, don't worry. However, there is
a way to install both IE4 and IE5 together on the same machine. Firstly,
you need to install a Windows operating system that does not have IE 5+
installed (NT4, 95, 98). You then need to install IE5 or IE5.5. Part way
through the install, one of the advanced configuration buttons lets you
choose to keep IE 4 in 'compatibility mode'. It is not as exact as it
should be, and sometimes, it screws up the installation, but it is quite
close to the behaviour of IE4 (no W3C DOM, no borders on headings/paragraphs,
scripting compatibility, etc.). I have found that sometimes it does not
apply filters when IE4 would have done, but that is about all.
Hope this helps
Tarquin