Link to home
Start Free TrialLog in
Avatar of diablomax
diablomax

asked on

Problem With The Pop-Up Window

Hello guys!

Here it is the pop-up window code that I want to use. It does exactly what I need.
So the images show in a pop-up as I need them to, but if the webpage is long and the link that you click on to open the image is somewhere down the page, when the pop-up shows up the webpage goes back to the top. That is very annoying as you might actually need to stay on the same spot on the page, so you don't want to have to scroll back to the place you were before clicking on each of those image links.

Could you guys PLEASE tell me what I have to do in order to keep the same spot on the page after you click on the image link, and it pops-up?!

Here it's the code:
===================

<!---Head--->
<script language="JavaScript">
<!--
function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {

if (bgcolor=="") {
bgcolor="#FFFFFF";
}
var adj=10, lift;
var w = screen.width;
var h = screen.height;
var byFactor=1;

if(w<740){
lift=0.90;
}
if(w>=740 & w<835){
lift=0.91;
}
if(w>=835){
lift=0.93;
}
if (imageWidth>w){
byFactor = w / imageWidth;
imageWidth = w;
imageHeight = imageHeight * byFactor;
}
if (imageHeight>h-adj){
byFactor = h / imageHeight;
imageWidth = (imageWidth * byFactor);
imageHeight = h;
}

var scrWidth = w-adj;
var scrHeight = (h*lift)-adj;

if (imageHeight>scrHeight){
imageHeight=imageHeight*lift;
imageWidth=imageWidth*lift;
}

var posLeft=0;
var posTop=0;

if (hugger == "hug image"){
if (hugMargin == ""){
hugMargin = 0;
}
var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
if (scrHeightTemp < scrHeight) {
scrHeight = scrHeightTemp;
}
var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
if (scrWidthTemp < scrWidth) {
scrWidth = scrWidthTemp;
}

if (scrHeight<100){scrHeight=100;}
if (scrWidth<100){scrWidth=100;}

posTop = ((h-(scrHeight/lift)-adj)/2);
posLeft = ((w-(scrWidth)-adj)/2);
}

if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
imageHeight=imageHeight-adj;
imageWidth=imageWidth-adj;
}

var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1){
var args= new Array();
args[0]='parent';
args[1]=imageName;
var i ; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
} else {
newWindow = window.open("","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
newWindow.document.open();
newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');
newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Click screen to close" >');
newWindow.document.write('</td></tr></table></body></html>');
newWindow.document.close();
newWindow.focus();
}
}
//-->
</script>
<!---Body--->
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

<a href="#" onClick="JustSoPicWindow('myimage.jpg','640','480','RUNECENTRAL.TK • Click window to close','#FFFFFF','hug image','0');return document.MM_returnValue">click to view image</a>

=====================
This is all I need to fix to get my webpage up and running soon.

Thank You Very Much!!

Diablomax
Avatar of rrz
rrz
Flag of United States of America image

This is the JSP area. You should have asked this in  the JavaScript area. But here is my idea.
You have
><a href="#" onClick="JustSoPicWindow(.....
I would add a name.
><a href="#popup" name="popup" onClick="JustSoPicWindow
See, if that works.
Avatar of diablomax
diablomax

ASKER

Thanx RRZ!

I didn't realize that this is JSP, you are right I'll post my question there.
Thank you for the suggestion I'll try it.
Hello RRZ!

Your idea of adding a name works!!

THANK YOU VERY VERY MUCH!!
Actually it doesn't really work :-(

No matter where you are at the top of the page or at the bottom, always takes you at a certain point on the page... I don't know why it chooses that point, it's a little bit down, like scrolling almost one inch down the page.
So no matter where you are when you click on the link for the image to pop up, it takes you to the point where you would be if you scroll down about one inch.
You can create an anchor anywhere on your page. Use
<a name="anchorname">  
then in your link use  
><a href="#anchorname"  onClick="JustSoPicWindow(.....  
When the link is clicked, the particular part that the anchor references, should be displayed at the top of the browser window.
ASKER CERTIFIED SOLUTION
Avatar of _marko_
_marko_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello RRZ!!
Hello Marco!!

Marco! your solution works!! I tested couple of times just to make sure and it works, exactly the way I wanted.

THANK YOU VERY MUCH MARCO!!! That is what I'm using now.

RRZ! your solution works too, the one that you offered me first time, BUT it worked when I tested it stand alone on a test page. In combination with the other scripts that I have on my webpage didn't work, so looks like was conflicting with something there on the actuall webpage that I'm working on.

ANYWAY THANK YOU VERY MUCH RRZ!!

Guys! Thank You a BUNCH!! You were VERY HELPFUL!! :-)