David Lavender

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromDavid Lavender
ToMe
SubjectRefinements to Perfect Popup script?
Date28 June 2005 15:27
Dear Tarquin,

I just tried your self-sizing Perfect Popup script for images.
It works beautifully.
I've removed the self-centering bit (because I don't need it).
There are just two things I can think of that would make it "even more
perfect" for my purposes:

1. Auto-close prevents users from right-clicking to save images (an
advantage, of course, if you're trying to protect your content). I share
your open source philosophy and am happy for people to copy my images, but I
also want to avoid multi-pop up clutter. Would it not be possible for your
script to give the pop-up window a name, so that a second pop-up would
simply overwrite the first? (I use this method with my old pop-up script).

2. Just as a minor refinement, it would be nice to give the loaded image an
alt tag. I found an auto-sizing JavaScript that does this, but I'm not
competent to combine its methods with yours, and I prefer your script, not
least because it allows windows to open without JavaScript.

I you find time to consider any of this please let me know,

Meanwhile, many thanks for the excellent resource you provide at
http://www.howtocreate.co.uk/. I just found it, and I'm sure I'll often
return for the clear and very useful tutorials,

Regards,
David Lavender.
FromMe
ToDavid Lavender
SubjectRe: Refinements to Perfect Popup script?
Date28 June 2005 21:53
David,

> 1. Auto-close prevents users from right-clicking to save images

yeah. browsers can be dumb sometimes. they think a right click on a window
constitutes blurring it. weird.

> Would it not
> be possible for your script to give the pop-up window a name

easy. On this line:
var imgWin = window.open('','_blank',.....
change '_blank' to 'aNameOfYourChoice'

> 2. Just as a minor refinement, it would be nice to give the loaded
> image an alt tag.

Change this:
popImage(imageURL,imageTitle)
to this:
popImage(imageURL,imageTitle,altAttribute)
(or whichever version of the function you are using. same modification)

change this:
alt="Loading image ..."
to this
alt="'+altAttribute+'"

then when calling the link, use this:
onclick="return popImage(this.href,'Site author','A bucket of prawns');"


Hope this is what you needed.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromDavid Lavender
ToMe
SubjectRe: Refinements to Perfect Popup script?
Date1 July 2005 00:07
Hi Mark,

Thank you very much for that - the window naming was simpler than I 
thought - I guess even I should have been able to work that one out.

I can't seem to get the alt tag attribute to show.
I have an experimental page up at 
[URL]

It's not very important though.

I've tagged an alternative pop-up opener to the end of your script to open
windows of pre-defined dimensions.
The problem is that if someone opens the pop-up using your "popImage" script
(eg. via the image link) and then reloads this (named) pop-up using
my "launchwin" method (eg. via the text link), the pop-up size would remain
as it was set by your opener.

To get round this, I first check if the window is opened. If not, I open
window as normal. If the window is already opened, first I close it, then
reopen to my defined size.

I'm missing something though, because it only closes the window the second
time "popImage" is called (or the second time "launchwin" is called).

This is what the script looks like now:

[a large part of my script with the alt attribute modification]

//alternative method for size-defined pop-ups - D Lavender
var newwin = '';

function launchwin(winurl,winname,winfeatures){
 if(false == newwin.closed) 
 { newwin.close ();
  newwin = window.open(winurl,winname,winfeatures);
  if( newwin.focus ) { newwin.focus(); }
 return false; }
 else
{  newwin = window.open(winurl,winname,winfeatures);
 if( newwin.focus ) { newwin.focus(); }
 return false; }
  }
FromMe
ToDavid Lavender
SubjectRe: Refinements to Perfect Popup script?
Date1 July 2005 10:52
David,

> I can't seem to get the alt tag attribute to show.

Works for me. I disable images, and I see the alt attribute instead. Tested
in Opera, IE and Firefox. It will work in the others as well.

What did you mean by "show"? - exactly where did you want it to appear?

>  var newwin = window.open('','mini' ...

using "var" creates a local variable. This is not what you want.

>  if(false == newwin.closed)

try this (after making sure the other function does not use a local
variable):
if( newwin && !newwin.closed )


Tarquin
FromDavid Lavender
ToMe
SubjectRe: Refinements to Perfect Popup script?
Date2 July 2005 03:02
> What did you mean by "show"? - exactly where did you want it to appear?

@@ I meant it doesn't show on the tooltip when I mouse over the image (IE).

>>  var newwin = window.open('','mini' ...
> using "var" creates a local variable. This is not what you want.
>
>>  if(false == newwin.closed)
> try this (after making sure the other function does not use a local variable):
> if( newwin && !newwin.closed )

@@ Thanks for those pointers. Just a couple of  little glitches I'm still
working on. When I use "imagePop" to load an image into a pop-up that was
opened with "launchwin" it shows a scroll bar whether or not it's needed,
and I have to get the "newwin" variable to work across my frameset (because
pop-ups are launched from the left navigation frame) -  but it's almost
perfect now.

Many thanks, David
FromMe
ToDavid Lavender
SubjectRe: Refinements to Perfect Popup script?
Date2 July 2005 09:50
David,

>> What did you mean by "show"? - exactly where did you want it to appear?
>
> @@  I meant it doesn't show on the tooltip when I mouse over the image (IE).

Then you are using the wrong attribute. Alt is not supposed to make
tooltips, even though several browsers break that guideline. Alt is
supposed to provide information when the image _cannot_ be displayed. You
want the "title" attribute. (It doesn't work in Netscape 4, as if anyone
cares - that's why people started abusing alt in the first place.)
title="foo"

Do the same thing as we did with alt, but use the title attribute instead.

> When I use "imagePop" to load an image into a pop-up that was opened with
> "launchwin" it shows a scroll bar whether or not it's needed

you need to use scrollbars=no when opening the window. Although if it is
needed in the first one, you have no choice. Some browsers are smart enough
to remove the scrollbars. IE is not one of them.

> and I have to get the "newwin" variable to work across my frameset

if(parent.nameofleftframe.newwin&&!parent.nameofleftframe.newwin.closed){
    parent.nameofleftframe.newwin.close();
}


Tarquin
FromDavid Lavender
ToMe
SubjectRe: Refinements to Perfect Popup script?
Date2 July 2005 23:59
WONDERFUL! Perfect pop-ups at last!

"Non-JavaScript" compliant, working across frames, sharing windows, with
auto and defined dimensions, alt tags, tool tips and scrollbars when
required.

Many thanks, Tarquin, for getting me there.

For the scrollbars behaviour I inserted an external stylesheet into your
"imagePop" function with a scroll=auto body attribute (and custom scrollbar)
and made scrollbars=1 (otherwise they didn't show even when required for
some reason). Tested IE and Firefox only.

Now it's time I visited your site and learned some JavaScript basics!

Regards,
David.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.