JAVASCRIPT Question

vern

Dominus
Political User
#1
I have this code ... which when called pops up a bigger version of an image and resizes the a new window according to the size of the image.

------

<SCRIPT language="JavaScript">
<!-- Begin
function CaricaFoto(img){
foto1= new Image();
foto1.src=(img);
Controlla(img);
}
function Controlla(img){
if((foto1.width!=0)&&(foto1.height!=0)){
viewFoto(img);
}
else{
funzione="Controlla('"+img+"')";
intervallo=setTimeout(funzione,20);
}
}
function viewFoto(img){
largh=foto1.width;
altez=foto1.height;
stringa="width="+largh+",height="+altez;
finestra=window.open(img,"",stringa);
}
// End -->
//-->
</script>

-------

My problem is that the top and left edges of the window that pops up stilll has a bit of blank space. Anyone know how I could fix this? If anyone has code that does the exact same thing I'm trying to do, but better ... I'd appreciate it if you shared it with me.
 
C

concrete

Guest
#3
The reason is in the window.open method. As the window src is just an image, there is no html so margins dont come into it.

In your window.open argument

largh=foto1.width;
altez=foto1.height;
stringa="width="+largh+",height="+altez;
finestra=window.open(img,"",stringa);
Add the scrollbars argument;

largh=foto1.width;
altez=foto1.height;
stringa="width="+largh+",height="+altez + ",scrollbars=no";
finestra=window.open(img,"",stringa);
Even though the window doesnt display scrollbars, IE tends to leave the area free "in case" you need scrollbars. If you implicitly tell it not to, it wont
 

muzikool

Act your wage.
Political User
#4
I have a question regarding this exact issue. I'm using DreamWeaver creating some webpages with just HTML. I don't know JavaScript, but I would like the pic links to pop up in a new window sized to the image. Right now I've just got the image opening up in a normal browser window. Can someone walk me through how to do this, or point me to a good guide? Thanks!
 

vern

Dominus
Political User
#5
I got this fixed. If you haven't found an alternative to your problem ... here is the code... you only need to add this to <head> of your page.

<SCRIPT language="JavaScript">
function CaricaFoto(img){
foto1= new Image();
foto1.src=(img);
Controlla(img);
}
function Controlla(img){
if((foto1.width!=0)&&(foto1.height!=0)){
viewFoto(img);
}
else{
funzione="Controlla('"+img+"')";
intervallo=setTimeout(funzione,20);
}
}
function viewFoto(img){
largh=foto1.width;
altez=foto1.height;
stringa="width="+(largh)+",height="+(altez);
finestra=window.open(img,"",stringa);
var s = finestra.document.body.style;
s.margin = '0'; s.padding = '0';
}
</script>
I only had to add this to make the pop-up window resize correctly to the image.
var s = finestra.document.body.style;
s.margin = '0'; s.padding = '0';
You call the script like so:

<a href="javascript:CaricaFoto('images/pic00.JPG')">


Originally posted by muzikool
I have a question regarding this exact issue. I'm using DreamWeaver creating some webpages with just HTML. I don't know JavaScript, but I would like the pic links to pop up in a new window sized to the image. Right now I've just got the image opening up in a normal browser window. Can someone walk me through how to do this, or point me to a good guide? Thanks!
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,971
Messages
673,300
Members
89,016
Latest member
Poseeut