473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Popup window problem

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, 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.
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.
Here is the script:

<script type="text/javascript">

PositionX = (screen.width/20);
PositionY = (screen.height/20);
defaultWidth = 800;
defaultHeight = 800;
var AutoClose = true;
if (parseInt(navig ator.appVersion .charAt(0))>=4) {
var isNN=(navigator .appName=="Nets cape")?1:0;
var isIE=(navigator .appName.indexO f("Microsoft")! =-1)?1:0;}
var
optNN='scrollba rs=no,width='+d efaultWidth+',h eight='+default Height+',left=' +
PositionX+',top ='+PositionY;
var
optIE='scrollba rs=no,width=150 ,height=100,lef t='+PositionX+' ,top='+Position Y
;
function popImage(imageU RL,imageTitle){
if (isNN){imgWin=w indow.open('abo ut:blank','',op tNN);}
if (isIE){imgWin=w indow.open('abo ut:blank','',op tIE);}
with (imgWin.documen t){
writeln('<html> <head><title>Lo ading...</title><style>bo dy{margin:0px;} </styl
e>');writeln('< sc'+'ript>');
writeln('var isNN,isIE;');wr iteln('if
(parseInt(navig ator.appVersion .charAt(0))>=4) {');
writeln('isNN=( navigator.appNa me=="Netscape") ?1:0;');writeln ('isIE=(navigat o
r.appName.index Of("Microsoft") !=-1)?1:0;}');
writeln('functi on reSizeToImage() {');writeln('if
(isIE){');write ln('window.resi zeTo(100,100);' );
writeln('width= 100-(document.body. clientWidth-document.images[0].width);');
writeln('height =100-(document.body. clientHeight-document.images[0].height);'
);
writeln('window .resizeTo(width ,height);}');wr iteln('if (isNN){');
writeln('window .innerWidth=doc ument.images["George"].width;');write ln('windo
w.innerHeight=d ocument.images["George"].height;}}');
writeln('functi on
doTitle(){docum ent.title="'+im ageTitle+'";}') ;writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no"
onload="reSizeT oImage();doTitl e();self.focus( )">')
else writeln('</head><body bgcolor=000000 scroll="no"
onload="reSizeT oImage();doTitl e();self.focus( )" onblur="self.cl ose()">');
writeln('<img name="George" src='+imageURL+ '
style="display: block"></body></html>');
close();}}

</script>

And on the site i write this:

<a href="javascrip t:popImage('the image url','the popup window name')">click
here</a>

Apr 18 '06 #1
3 2155
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.appNa me 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.mozil la.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.ava ilWidth/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(navig ator.appVersion .charAt(0))>=4) {
var isNN=(navigator .appName=="Nets cape")?1:0;
var isIE=(navigator .appName.indexO f("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='scrollba rs=no,width='+d efaultWidth+',h eight='+default Height+',left=' +
PositionX+',top ='+PositionY;
var
optIE='scrollba rs=no,width=150 ,height=100,lef t='+PositionX+' ,top='+Position Y
;
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="javascrip t: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.h ref,'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.c om/FAQ>
Apr 19 '06 #2
Instead of trying to determine the size of the image client side, do it
server side. Since you're not familiar with JavaScript, maybe this VB
code will point you in the right direction:

http://www.effengud.com/articles/imgsz.html

I did not write it, but with this script slightly modified, you can set
the size of the window as the images are dynamically called. I have
used this code on my own sites and it works fantastic. Also, doing it
server side eliminates your issue of it being W3C compliant as the
window will already be correctly sized before displaying the picture.
Adding the functionality to close the window onblur should not be an
issue after that.

If you want to see it in action, send me an email and I will provide
you with a link to a sample that should give you a better idea of how I
actually utilized it.

Scott

Apr 19 '06 #3

"EnjoyNews" <a@a.dk> skrev i en meddelelse
news:44******** *************@d read14.news.tel e.dk...
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, 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.
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.


Hi again

I have now read your answers and I have have read about javascript on the
pages your link to.
I'm a not used to javascript at all, so right now I am a little confused
:o)))

I can see now that the script I have on my site is not very good, so I need
to have a brand new one.
But it is just to difficult for me I must admit. I'm not very good at
scripting.. :o((

So therefore I will ask if someone could please help me by write some
javascript lines for me... I have very few things I want it to do, so I
don't think it is to difficult for someone who is good at it.

It is a image popup.
A link with <a href="image.jpg " onclick="someth ing">Click here</a>

I won't it to put up in a new window without scrolling and statusbar. It
must be resizeable=no
The tricky part is that the window must be the same size as the image, and I
want it to close automaticly when you click outside the window.
This is what I can't figure out. ?

The posotion is not important, but if it could be place in the middle of the
screen it would be nice, but it isn't important.
If someone could help me with this I would really really apreciate it.
thanks in advance

Michael
Apr 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
11571
by: Willem van Isselmuden | last post by:
Hello, I've a problem I hava a page with different popup windows, when I hit a link the first one pops up and with the first open i would like to hit the second link in the parent page so the second links pops up a window in the first popup. The way I have it now is working but with each link the size of the popup window should be...
38
5024
by: Shaun McKinnon | last post by:
HI...Here's my problem...I have a popup window that loads when i want it to, but it's not sized properly. I've set the size, but it doesn't seem to work. I've been on 8 different websites to find out what i'm doing wrong, and so far it seems i'm doing it the right way. Here's my code...any suggestions would be appreciated. <script...
12
12406
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank, 'height=200,width=400,status=no,toolbar=no, menubar=no,location=no resizable=no scrollable=no'); but I can't seem to invoke the client side script from within a Server...
17
2502
by: Applebrownbetty | last post by:
Hi, I'd like to append/amend the following code from the Dreamweaver extension "Open Picture Window Fever" for the ability to center the PopUp window: By default, it allows the window to be offset on the left and top, but does not include a centering option. I'm thinking it would include something like (screen.width-imageWidth)/2;...
7
3208
by: E Michael Brandt | last post by:
I have been lurking here for some time, and now would like to ask a question of you clever coders: My JustSo PictureWindow 3 Extension for Dreamweaver has stumbled in the face of the new Opera 8. Jspw3 opens a popup window (using varname=window.open(...)) but there are now two problems: 1) Opera8 interprets a top,left of 0,0 to be top...
4
2419
by: VR | last post by:
First, greetings to everyone :) I'm doing a university seminar & I've encountered a problem. I have a gallery with thumbnails linked on pictures. What I want is popup to be opened with dimensions of linked picture after clicking on a thumbnail. I found javascript which is compatible with IE, Firefox & Opera but I can't get it to work. All...
3
1984
by: ypress | last post by:
Hi. I have a page that contains this simple function: <script language="javascript"> function openPop(url, name, w, h) { var features = ""; features += "scrollbars=no,"; features += "menubar=no,"; features += "resizable=no,";
11
7324
by: Alex.Svetos | last post by:
Hello, I'm trying to get a popup to keep focus when it is re-clicked. The script below is supposed to produce this exact behaviour, however it doesn't work, at least on firefox 1.0.7 and moz 1.7.12 (linux kubuntu). It does work with konqueror. It seems to work with firefox on windows but not with IE (not completly sure though).
7
3655
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses pageA.html 2. User clicks on menu link to open popup.html 3. pageA.html checks if popup.html is already open. It is not, open
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.