Click to See Complete Forum and Search --> : Can you use open.window() with....


ricpa
12-05-2003, 09:11 AM
an image link?
This is my first post and I'm having a problem with a few images. On a page on the site I have a few small pictures that show a texture. Is it possible to use window.open() to click on the image so that a new window opens showing the larger image. I know I can use target="_blank" but I want to have a window that is just big enough to fit the picture in.

TheBearMay
12-05-2003, 09:28 AM
Yes.

window.open("http://yourImageHere.jpg",winName,"width=600, height=400....");

ricpa
12-05-2003, 10:07 AM
So where do I put this line of code. I need to click on an image, which will open another window with another picture in it. I've tried what you said but I'm having no luck.

ricpa
12-05-2003, 10:15 AM
I think I managed it with this code

<a href="#"
onClick="window.open('pix/finish/diamante.jpg', 'Diamante', 'toolbar=0, status=0, width=250, height=166');">
<img src="pix/finish/diamante_small.jpg" border="0",></a>
However I'm sure there is a better way of doing it. Surely I don't have to use the "#" in the link section just to stop the browser opening another page? Another thing is that the picture is surrounded with white space above and to the left of it. The size of the image is w250 x h166 so what is the problem there?

pixelmech
12-05-2003, 10:38 AM
Originally posted by ricpa
I think I managed it with this code

<a href="#"
onClick="window.open('pix/finish/diamante.jpg', 'Diamante', 'toolbar=0, status=0, width=250, height=166');">
<img src="pix/finish/diamante_small.jpg" border="0",></a>
However I'm sure there is a better way of doing it. Surely I don't have to use the "#" in the link section just to stop the browser opening another page? Another thing is that the picture is surrounded with white space above and to the left of it. The size of the image is w250 x h166 so what is the problem there?

Ricpa,

What you really want to do is write a function to handle this for all your images, then call the function.


function ShowImageWin(imgPath, imgName, w, h)
{
//constants definitions
var POPUP_WIDTH = w;
var POPUP_HEIGHT = h;

//the center properties
var window_width = POPUP_WIDTH;
var window_height = POPUP_HEIGHT;
var screen_balance_w = ((screen.width)-(window_width))/2;
var screen_balance_h = ((screen.height)-(window_height))/2;
var set_top = screen_balance_h;
var set_left = screen_balance_w;

win = window.open(imgPath,imgName,'width=' + window_width + ',height=' + window_height + ',top=' + set_top + ',left=' + set_left + ',menubar=yes, resizeable=yes, scrollbars=yes');
win.focus();
}


That should work for you, pass the image path and name, and even width and height if you want (or make them static). The function will also center the window on the screen.

Then in your link, call it correctly:


<a href="imagePathHere" onClick="ShowImageWin('image.jpg', 'myImage', 600, 400); return false;">
<img src="pix/finish/diamante_small.jpg" border="0",></a>


This is accessible to someone w/o JS or JS disabled. The return false will disable the link for JS enabled users. Otherwise, the user will still get your bigger image, just on a new page. They can then click the back button. Works for everyone.

HTH

Tom

ricpa
12-05-2003, 10:42 AM
cheers mate that looks just the ticket!

ricpa
12-05-2003, 11:12 AM
I've just realised that you've put that code in PHP but I'm using ASP. I don't suppose there's any chance that will work will it?

pixelmech
12-05-2003, 12:51 PM
Originally posted by ricpa
I've just realised that you've put that code in PHP but I'm using ASP. I don't suppose there's any chance that will work will it?

It's neither, its JavaScript :) Client side, not server side.

Tom

ray326
12-05-2003, 01:51 PM
Originally posted by ricpa
I've just realised that you've put that code in PHP but I'm using ASP. I don't suppose there's any chance that will work will it?

That PHP tag was just used so the code would be formatted a certain way. It doesn't mean it's PHP code.

ricpa
12-05-2003, 02:24 PM
oh I get it! :rolleyes: