Click to See Complete Forum and Search --> : can't get var passed to window.open in a function


agminer
10-20-2003, 03:57 PM
I am trying to reduce the amount of code on the web page by creating a function for the onclick window.open.
In passing the file name and dimensions I can't get the function to work

function showimg(pic,wdth,hght)
{
window.open('"showgallery.html?"+pic+"%"+wdth+"#"+hght','alternate','resizable,width=540,height=510').focus();
}



This can be viewed at http://home.mchsi.com/~auminer/etc/aands/indwedding.htm

Pic #1 is hard coded #2 is the function that I can't get to work and #3 is the original code

Roger

Phil Karras
10-20-2003, 04:24 PM
In the window that is the parent use:

<head>
<script ....
var Width = 123;
var Height = 96;

// or whatever you want.
.
.
.
Now, in the child window (the one you just opened) use:

var MyHeight = window.opener.Height;
var MyWidth = window.opener.Width;

That's a bit easier isn't it? Your way can work by the way, but this was made to work this way in JavaScript, so why not use it?

David Harrison
10-20-2003, 05:00 PM
Or you could do:

document.writeln('<script type="text/javascript"><!--');
document.writeln('var height=123;');
document.writeln('var width=96;');
document.writeln('//--></scr'+'ipt>');

agminer
10-20-2003, 06:08 PM
Each image might have different height and width, this is the reason for having the variables in the first place. It looks to me that your solutions will set a standard size for all pictures.

Phil Karras
10-20-2003, 06:47 PM
I did set the original values but as in all things programming, they can be changed at will as easy as you were going to change yours:

var Height = 123;
var Width = 96;
function OpenNewWin(height, width) {
Height = height;
Width = width;
window.open(...);
}

agminer
10-20-2003, 11:33 PM
The reason for passing the var's is to end up creating a string simalar to showgallery.html?img_7356%515#342 as part of the window .open() method.

In the new window, the showgallery.html opens up, knows ich img to use and how large to make a frame around that img.

When I try concatating the string the window open has not been working for me.

David Harrison
10-21-2003, 11:08 AM
Well here's a little script that will allow you to open various sized preset windows, or open your own custom sized window.

agminer
10-21-2003, 12:18 PM
If the page I posted is checked out it can be seen that I use a standard size window to display an "enlarged" image. But the images are not all the same and I try to have a border around the image itself. This is where I have had difficulty in passing the image size from the onclick through the function to the html that displays the image.

David Harrison
10-22-2003, 01:19 PM
The script that I posted lends itself to modification. I have changed it so that an image of your choosing appears with various sizes and a 2px border. I have also centred it horizontally and vertically on the new page.

Khalid Ali
10-22-2003, 04:17 PM
1.thre is something wrong in here.

to me it seems like that you have a page

showgallery.html,
in this page you have code that parses the URL and then gets the image to display,and all other properties and shows the image??????(is this correct)


2.If the above is not correct and you are simply trying to view an image that you want to open up in a popup window by clicking on a link or a thumbnail,then your code is wrong.
If intention is as what I described above
in item 2

then the following will open up a popup window with the passed image src.

function showimg(pic,wdth,hght){
var winProps = 'width='+wdth+'height='+hght,resizable=yes';
window.open(pic,'newWin',winProps).focus();
}
in the above pic should point to a valid url
url = images.some.gif

David Harrison
10-22-2003, 05:13 PM
Are you referring to my script or agminer's?

I think the chances are tha you are referring to agminer's since you mention parsing URL's but if you are talking about mine, then rest assured I'm not just opening the pic, I'm creating the and and including an img tag in it for the image. The window is a constant size and it is the width and height of the image that changes (via inline styles).

agminer
10-22-2003, 06:08 PM
#1 I am trying to click on thumbnail, pass img name and size to html in new window, parse for name and size (name to display and size to set a frame around it) since this is a gallery I am trying to use the same window each time and not have to have a separate html page for each image.

Again when I "hard" code it but when I try to pass the variables and concatate the window.open does not work for me.

David Harrison
10-22-2003, 06:33 PM
I have posted a solution that you can use, so you can feel free to use that. If you really want to use a pre-coded page then I will have to let Khalid Ali take over from here because I have to go offline about 1.5 hours ago.

Khalid Ali
10-22-2003, 07:12 PM
ok so you are trying to open an image by passing the paramers to the page using URL first toast the
window.open()

use this

window.location.href = "gallerypage.html?imageSrc="+pic+"&width="+width+"&height="hght; and so on appaend as many props you want.
For this approach,its important that you showed what is the code thats parsing the URL

agminer
10-22-2003, 08:47 PM
I take it that creating a string and stuffing it in the window.open() is not possible.

I am having a hard time picturing how to use the location, I thought that was from within a window and not stuffing another window. If it is from within a window how do I read the values from the onclick in the first window (wich is in a frame)?

Phil Karras
10-23-2003, 08:38 AM
Just a bit of info for you, I have a good demo of passing data between pages/windows/frames located at: http://cs.yrex.com/index.htm Look in the table, at the left colum, second item down:
Data Passing
Hope that helps.

agminer
10-26-2003, 08:25 PM
After going back to square 1 I found that I had left the quote marks out of the function call parameters.

Function( 'img', 'w', 'h' )

After putting them in the code worked as planned (with minor corrections)