Jerry Obrecht

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJerry Obrecht
ToMe
Subjectscript modification needed
Date14 September 2004 06:13
Attachmentpage showing my example script working
Hi I am trying to adapt one of your scripts.

1. Script I need help with:
http://www.howtocreate.co.uk/perfectPopups.html
function openPerfectPopup(oW,oTitle,oContent)

2.  URL where I am trying to use it:
I have not yet uploaded the site to a webspace, but I have provided the
attached zipped files.

3.  What I want to do with it:
I would like to adapt oContent so that I can use xhtml (div & span tags) in
the content area, and not just html/text.

4.  What you are having problems with:
When I try to place the entire contents of the page in the oContent areaof
the link, the " " in <div class=" "> causes the script to document.write the
actual code.

I would like to achieve the same effect that the image popup gives, but with
my email form page.

The email form page is currently opened by another popup script with width
and hieght set manually. I actually have two form pages. One for feedback
and one for proper enquiries both having a different height.
I also realise that form elements are displayed differently in many browsers
causing the page to increase or decrease in height. Making the window fit to
its loaded size would be great.

If adapting oContent is not possible can you please explain another option
for my situation?
Maybe it is possible to implement a javascript include file in some way.
Or just opening the form page in a popup window and then resizing it after
it loads. I have tried the script at the bottom of your popups page that
resizes an already open window page, but I cant get it to work properly with
my form pages.

Thank you very much,
Jerry Obrecht
FromMe
ToJerry Obrecht
SubjectRe: script modification needed
Date14 September 2004 08:50
Jerry,

I'm trying to work out exactly where your problem lies.

From the sound of it, the simplest form of the problem would be
demonstrated like this (excuse the linewrapping):

<a href="noPop.html"
onclick="return openPerfectPopup(300,'Title','<div class=" "></div>');">
feedback form</a>

At which point, I see the code appear on the page. If this is your problem,
the reason is fairly simple. The HTML attribute is delimited with the "
character and you are trying to put a " inside the attribute, which is
invalid. What you should do is to use HTML entities within an attribute, as
this is what is required by the (X)HTML spec:

<a href="noPop.html"
onclick="return openPerfectPopup(300,'Title','&lt;div class=&quot; &quot;&gt;&lt;/div&gt;');">
feedback form</a>

Looks messy huh?

ok, so save the content as a JavaScript variable:
var newContent = '<div class=" ">it\'s valid to use quotes here</div>';

then call the function using the variable instead (notice the lack of
quotes)

<a href="noPop.html"
onclick="return openPerfectPopup(300,'Title',newContent);">
feedback form</a>

Hope this helps, but if I have misunderstood, please send me a copy of the
page with the script not working properly on it, and I will debug it.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJerry Obrecht
ToMe
SubjectPerfect Image Popup - Possible Enhancement
Date7 November 2004 08:36
Hi, I really like your popup script for auto resizing a window to fit an image 
and centering it in the screen. I have however run into an issue.

Your Script:
Perfect Popup / Resizing to fit an image

Issue:
On the webpage below I have 4 thumbnails that open the popup window with a 
larger version of the image. The second thumbnail opens an image that is larger 
than my screen size (1024 x 768). Is it possible to keep the window from opening 
any larger than the screen width/height and diplay a scroll bar to compensate 
for the oversized image. Normally I would just make the image smaller, but in 
this circumstance it would become to small for proper legability.

Possible enhancement:
Limit the popups maximum size to that of the screen even if the image is larger 
than the screen size.

Webpage with issue: [page showing the problem]

.js file: [script file being used]

Thanks for your help,
Jerry Obrecht
FromMe
ToJerry Obrecht
SubjectRe: Perfect Image Popup - Possible Enhancement
Date7 November 2004 11:47
Jerry,

The scrollbar is actually hidden at the time the window is opened, so you
would need to make sure the window was opened with a scrollbar. There is
not much that I can do to change that, as showing a scrollbar _after_ the
window has been opened requires elevated privileges (don't ask why, it is
just some strange security measure that was written into the JavaScript
language).

I have already shown how to make a similar modification for someone else:
http://www.howtocreate.co.uk/emails/AdamWoods.html
but that also resized the image. This will probably do what you want:

after this line:

'var oH = document.images[0].height, oW = document.images[0].width;\n'+

add this (you may need to play with the numbers in the first line):

'var mH = screen.availHeight-50, mW = screen.availWidth-40;\n'+
'if( oH > mH ) { oH = mH; }\n'+
'if( oW > mW ) { oW = mW; }\n'+

Hope this does what you need

Tarquin
FromJerry Obrecht
ToMe
SubjectRe: Perfect Image Popup - Possible Enhancement
Date7 November 2004 18:40
Just wanted to tahnk you for the help.

Works great.

  Jerry Obrecht
FromJerry Obrecht
ToMe
SubjectPerfect Image Popup - I added an animated Loading.gif
Date7 November 2004 21:40
Hi,

I added an animated loading gif to your perfect popup. I placed it in the
absolutely positioned div as a css background image. 

I saw a loading gif on another similar popup and have been wanting to
figure out how to do the same with yours ever since. I finally realised
that I could, but in a more simple way. Their popup wasn't using a div and
the gif did not disappear after window resize, but was replaced by another
image (Image loaded). It may have been displayed dynamically.

Your popup is in fact perfect as far as I am concerned.

You are more than welcome to use the loading gif enhancement if you like.
Just view the script on this page:
[script address]

You can test it out on this page:
[test page]


Thanks again,
Jerry Obrecht
FromMe
ToJerry Obrecht
SubjectRe: Perfect Image Popup - I added an animated Loading.gif
Date8 November 2004 15:08
Jerry,

Just a comment about the code you are using, I notice you have included a
strict doctype tag in the popup code. While there is nothing inherently
wrong with this, you have neglected to make the image display:block;

As a result, Opera will show a scrollbar, as it correctly leaves a gap
under the image for tails of text characters that appear below the baseline.
Surprisingly Mozilla/Firefox incorrectly do not leave this gap, because
they ignore your strict doctype and are rendering in quirks mode (sounds
like a Gecko bug to me - I will check and file a bug report if necessary).
The solution is to add:
style="display:block;"
to the image tag.

I have now added a comment about this to the article.

Tarquin
FromJerry Obrecht
ToMe
SubjectPerfect Image Popup - Optional scrollbars resizable
Date9 November 2004 2:36
Hi,

Sorry to bother you again.
I found a way to change the scrollbars and resizable settings from the the
image tag when limiting the perfect image popup height and width to maximum
screen size . This might be of benefit as it allows you to change the
settings for each individual image popup without having to change it in the
script, which changes it for all image popups.

I have uploaded it to the following links.

.js file: [script that passes the scrollbar option as a parameter to the
function that opens the popup]

test page: [test address]

Notice that the first thumbnail opens with no scrollbars and the second with
scrollbars.

I have also added the display:block; to the image tag as you suggested.

Unfortunately it works fine with the files on my computer, but it doesn't
seem to work with the files that have been uploaded to the server. Maybe
they have not refreshed or the old ones are still in cache. I hpe it worksfor you.

Thank you for the great popup again,
Jerry Obrecht
FromMe
ToJerry Obrecht
SubjectRe: Perfect Image Popup - Optional scrollbars resizable
Date9 November 2004 15:06
Nice neat solution.

Yes, the image worked perfectly for me in Opera, scrollbars correctly
appeared or did not appear depending on image size. perfect.

I also worked out why Mozilla/Firefox do not use strict rendering mode. It
is a bug in the Gecko engine, that if you write the <?xml and the <!doctype
tags with two separate document.write commands, it will use the wrong mode.
If you use just a single document.write command to replace the first two
that you have used, it will work fine. I reported this bug to Mozilla.
https://bugzilla.mozilla.org/show_bug.cgi?id=268442

Tarquin
FromJerry Obrecht
ToMe
SubjectRe: Perfect Image Popup - Optional scrollbars resizable
Date10 November 2004 3:25
Hi,

I have found some specific browser related issues that could be improved if
possible. However I do not want you to feel as though you need to do it. I
am only requesting this if you have time and want to make the changes.

- Opera place the image popup in upper left corner below the tab bar istead
of centering it on the screen (you are unable to drag the window above the
tab bar).

Can image popup be centered, or is the PositionX = 10; PositionY = 10; in
the script the best that can be acheived for Opera, and not just for all
popups when first opened? Is this what you mean by (the first two should be
small for Opera's sake)?

I took another look at the script and commented out 3 of the 4 lines below.
Now Opera 7.5 centers the image popup. Is their a reason for not
document.writing this code for Opera too.

//imgWin.document.write('if( !window.opera )');
//imgWin.document.write('{');
imgWin.document.write('x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2));');
//imgWin.docum ent.write('}');

Operas - Tools > Preferences > Windows > Window Handling > Prefer Seperate
Windows - causes the image popup to appear at the very top left of the
screen above tab bar.

Opera - Tools > Preferences > Windows > Window Handling > Prefer Pages
Inside Window - cause it to position in top left corner just below the tab
Bar (in current window).

Can javascript override this Preference setting without having to change it
manually?

- Is there a way to keep Opera 7.5 from displaying the download status bar
at the bottom or at least add extra space to the height if the browser is
Opera. When parent page loads this bar disappears. It seams as though Opera
does not think that the image popup has loaded.

- I noticed that Netscape 7.1, Firefox 1.0 and Opera 7.5 do not use the
maximum height portion of the script properly when limiting the image popup
to the screen height and width -75. It extends off the bottom of the screen.
// var imgwin must be set to scrollbars=yes if an image is going to be larger than the screen.
// Next 3 lines keep popup from being larger than screen when image is larger than screen.
imgWin.document.write('var mH = screen.availHeight -75, mW = screen.availWidth -75;');
imgWin.document.write('if( oH > mH ) { oH = mH; }');
imgWin.document.write('if( oW > mW ) { oW = mW; }');

Thanks for your help. Hope I am not bothering you, just encouraging an even
more perfect popup. LOL


  Jerry Obrecht
FromMe
ToJerry Obrecht
SubjectRe: Perfect Image Popup - Optional scrollbars resizable
Date10 November 2004 9:06
> I took another look at the script and commented out 3 of the 4 lines
> below. Now Opera 7.5 centers the image popup. Is their a reason for not
> document.writing this code for Opera too?

Yes there is a reason. Opera offers two modes, MDI (Tabs plus workspace)
and SDI. In SDI, the centring works perfectly. In MDI, Opera reads the
available size as being the size of the screen, then actually positions
them relative to its inner workspace, meaning that the edges of the popup
are put too far off the side of the workspace, and the buttons to maximize,
minimize and close the window are not visible. This is a slightly annoying
feature in Opera, and there is no way to know which MDI/SDI mode is being
used, so to prevent this annoyance (for the sake of Opera users), I do not
centre the popup in Opera. I have asked them to report the available size
to be the size of the workspace when using MDI, maybe this will be
included in a future release.

> Opera - Tools > Preferences > Windows > Window Handling > Prefer Pages
> Inside Window - cause it to position in top left corner just below the
> tab Bar (in current window).
> Can javascript override this Preference setting without having to change
> it manually?

Absolutely not. Opera allows the user to have the control (as an Opera user
myself, this is something I find very useful). The web page should never be
allowed to dictate my preferences, especially not when it comes to handling
popups and extra windows.

> Is there a way to keep Opera 7.5 from displaying the download status bar
> at the bottom

no, this bar in in the user's control. they can choose to have the bar
displayed at the bottom, or replacing the address bar or not to appear. I
have mine set not to appear, and I do not want an ugly gap in mine. In
Opera 7.6, they may be including the progress bar (that is the name they
use for it) within the address bar.

> It seams as though Opera does not think that the image popup has loaded.

Funny, I saw this behaviour with your image popups in Firefox. But both
Opera and Firefox work perfectly fine with mine. Maybe there is a header
issue ... *fires up curl* ... nope, not headers. hmm, I see you neglected
to close the document stream after writing the popup contents:
imgWin.document.close();
This is probably the reason.

> I noticed that Netscape 7.1, Firefox 1.0 and Opera 7.5 do not use the
> maximum height portion of the script properly when limiting the image
> popup to the screen height and width -75. It extends off the bottom of
> the screen.

Seems like you have to take a lot of height off doesn't it. I guess you
will have to use -100 or thereabouts (this number is to allow space for
the toolbars). Initially positioning it at 0,0 instead of 10,10 will have a
better effect in Opera.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.