Re: Popup window problem
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Tue, 18 Apr 2006 23:58:13 GMT
EnjoyNews said on 19/04/2006 5:48 AM AEST:
I have a popup problem.
I have a script that generates a popup for image viewing.
It has 2 function, and the first is that it automaticly generates the popup
window to the size of the image, and the second is that it closes the popup
window when you click outside of it.
It is a script I have found on the internet, since I have no experience in
javascript coding.
It works fine,
No, it doesn't, you just haven't found where it fails. Try it in a browser whose navigator.appName string doesn't contain either "Netscape" or "Microsoft" or has a version number less than 4 (there are lots of those).
but the site won't go through a w3c validation.
In the script there are some body, title, head tag's which the validation
won't exept.
It looks like it can't see that it is inside a script, and think it's a body
tag that is suddently in the middle of the site, which it ofcause won't
exept.
"Accept". Put the script in an external file, then the validator won't see it.
So I need a little help with this one.
Or maybe if it's an older script, and someone knows a better and newer one
that can do the job.
Search the archives for pop-up scripts, there are many that are better than the one below. Read the stuff here:
<URL:http://developer.mozilla.org/en/docs/DOM:window.open>
Here is the script:
<script type="text/javascript">
PositionX = (screen.width/20);
PositionY = (screen.height/20);
Variables should always be declared with 'var'. There is no need to make these global variables, keep them local to the function.
It is a convention that variables starting with capital letters can be used as constructors, so make the first letter lower case.
Don't presume to know where the user wants the popup (if they allow it at all). Just let it go where it wants - remember you are dealing with screens that are generally anywhere from 800 to 1600 pixels wide (and some are very much wider than that - e.g. one desktop across two screens of 1600px each). Let the user put the pop-up whee they want, then re-use it.
The property you are probably looking for is:
var positionX = self.screen.availWidth/20;
which will allow for screen features that take up space (e.g. Mac menu bar & doc, Windows start bar).
defaultWidth = 800;
defaultHeight = 800;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
Browser sniffing is bad, just don't do it. This will exclude some browsers for no good reason as noted above.
var
optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+
PositionX+',top='+PositionY;
var
optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY
;
I'm curious why browsers that you think are 'Netscape' get a window 8 times higher and nearly 6 times wider than what you give to those you think are IE (noting that the UA string may have no bearing at all on which browser is actually being used).
Replace the script with something from the references above.
[...]
And on the site i write this:
<a href="javascript:popImage('the image url','the popup window name')">click
here</a>
And if scripting is disabled, the user sees nothing. Use:
<a href="image.jpg"
onclick="return popImage(this.href,'the popup window name')">Click
here to open image in a popup</a>
Have popImage() return false if the popup is successfully opened, otherwise return true and the link will be followed. It is much more efficient to have the server generate HTML for the popup; have the client supply just the URL, not all the HTML as well.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
.
- References:
- Popup window problem
- From: EnjoyNews
- Popup window problem
- Prev by Date: Re: forms, radio buttons and setting values
- Next by Date: hidden/visible divs
- Previous by thread: Popup window problem
- Next by thread: Re: Popup window problem
- Index(es):