Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > PROBLEM: window.open & accessing parent variables' values

Reply
Thread Tools

PROBLEM: window.open & accessing parent variables' values

 
 
Jiri Brada
Guest
Posts: n/a
 
      04-05-2004
Hi,

I have got a following problem with using Javascript:

I have a HTML page with pictures' thumbnails. After clicking on any
thumbnail, I would like to open a new window with the original size
picture. In the main window with thumbnails, I have got following
important stuff:

<SCRIPT LANGUAGE="JavaScript">

var images = new Array (
"2004_Croatia_Brela/Croatia_Brela_083.jpg",
"2004_Croatia_Brela/Croatia_Brela_090.jpg",
"2004_Croatia_Brela/Croatia_Brela_107.jpg",
"2004_Croatia_Brela/Croatia_Brela_108.jpg"
);
var image_count = images.length-1;
var pImageNumber = 0;

function show_image( pImageNumber ) {

var pFile = new Image();
var ht = 0;
var wd = 0;

for ( var i=0; i<image_count; i++ ) {
pFile.src = images[i];
if ( pFile.height > ht ) ht = pFile.height;
if ( pFile.width > wd ) wd = pFile.width;
}

pFile.src = images[pImageNumber];
ht = ht + 20 + 40;
wd = wd + 20;

imagewindow = window.open( "GSET_Croatia_Brela_images.htm", "img",
"innerWidth=" + wd + ",width=" + wd + ",innerHeight=" + ht +
",height=" + ht + ",resizable,left=20,top=20");

// this is commented because I always get a script
// error that "imagewindow.document.images.changing_image" is
// null or does not exist - is it because the new page is not loaded
yet?

//imagewindow.document.images.changing_image.src = pFile.src;
//imagewindow.document.images.changing_image.width = pFile.width;
//imagewindow.document.images.changing_image.height = pFile.height;
//imagewindow.document.image_number = pImageNumber;
}
</SCRIPT>

and somewhere in the body I have got

<a href="2004_Croatia_Brela/Croatia_Brela_107.jpg"
onClick="show_image(2); return false;"><img
src="2004_Croatia_Brela/Thumbnail_Croatia_Brela_107.jpg" width="154"
height="115" border="0"></a>

Now, the new page with original images (GSET_Croatia_Brela_images.htm)
looks like:

<html>
<head>
<title>GS Radov&aacute;nky</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link href="Assets/GSET_CSS_Style.css" rel="stylesheet"
type="text/css">
<SCRIPT LANGUAGE="JavaScript">

var images = new Array (
"2004_Croatia_Brela/Croatia_Brela_083.jpg",
"2004_Croatia_Brela/Croatia_Brela_090.jpg",
"2004_Croatia_Brela/Croatia_Brela_107.jpg",
"2004_Croatia_Brela/Croatia_Brela_108.jpg"
);
var image_number = 0;
var image_count = images.length-1;
var current_image = new Image();

function PreviousImage ( ) {
image_number--;
if ( image_number == -1 ) image_number = image_count;
current_image.src = images[image_number];
document.images.changing_image.src = current_image.src;
document.images.changing_image.width = current_image.width;
document.images.changing_image.height = current_image.height;
}
function NextImage ( ) {
image_number++;
if ( image_number == image_count+1 ) image_number = 0;
current_image.src = images[image_number];
document.images.changing_image.src = current_image.src;
document.images.changing_image.width = current_image.width;
document.images.changing_image.height = current_image.height;
}
function ActualImage ( ) {
image_number = opener.pImageNumber;
current_image.src = images[image_number];
document.images.changing_image.src = current_image.src;
document.images.changing_image.width = current_image.width;
document.images.changing_image.height = current_image.height;
}
</SCRIPT>
</head>
<body onLoad="ActualImage(); return false;">
<table align="center" cellspacing="0">
<tr>
<td align="center" valign="middle"><img name="changing_image"
src="Images/Empty_image.jpg" onClick="NextImage();" width="640"
height="480" alt=""></td>
</tr>
<tr>
<td align="center" valign="middle"><table align="center"
cellspacing="10">
<tr align="center" valign="middle">
<td class="white_link"><a href="#"
onClick="PreviousImage();">Previous</a></td>
<td class="white_link"><a href="#"
onClick="NextImage();">Next</a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>

So, I though that by using the onLoad function for body I could set
the correct image from the list (which is the same as the list on the
thumbnail page, maybe uselessly?) by using image_number =
opener.pImageNumber in the ActualImage function executed within
onLoad, but is simply does not work.

Do you have any idea what I am doing wrong? I thought that by using
opener keyword and image_number = opener.pImageNumber I would be able
to find out what value was used for running the show_image (
pImageNumber) on the main page.

Thank you for any help in advance.

Jiri
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      04-05-2004
On 4 Apr 2004 21:56:57 -0700, Jiri Brada <(E-Mail Removed)> wrote:

> <SCRIPT LANGUAGE="JavaScript">


The language attribute is deprecated. You should use the required type
attribute:

<script type="text/javascript">

> var images = new Array (
> "2004_Croatia_Brela/Croatia_Brela_083.jpg",
> "2004_Croatia_Brela/Croatia_Brela_090.jpg",
> "2004_Croatia_Brela/Croatia_Brela_107.jpg",
> "2004_Croatia_Brela/Croatia_Brela_108.jpg"
> );


It's probably better to use the array literal notation:

var images = [ '2004_Croatia_Brela/Croatia_Brela_083.jpg',
'2004_Croatia_Brela/Croatia_Brela_090.jpg',
'2004_Croatia_Brela/Croatia_Brela_107.jpg',
'2004_Croatia_Brela/Croatia_Brela_108.jpg' ];

[snipped beginning of show_image()]

> imagewindow = window.open( "GSET_Croatia_Brela_images.htm", "img",
> "innerWidth=" + wd + ",width=" + wd + ",innerHeight=" + ht +
> ",height=" + ht + ",resizable,left=20,top=20");
>
> // this is commented because I always get a script
> // error that "imagewindow.document.images.changing_image" is
> // null or does not exist - is it because the new page is not loaded
> // yet?


Yes, precisely.

[snip]

> <SCRIPT LANGUAGE="JavaScript">
>
> var images = new Array (
> "2004_Croatia_Brela/Croatia_Brela_083.jpg",
> "2004_Croatia_Brela/Croatia_Brela_090.jpg",
> "2004_Croatia_Brela/Croatia_Brela_107.jpg",
> "2004_Croatia_Brela/Croatia_Brela_108.jpg"
> );


As above.

[snip]

> <body onLoad="ActualImage(); return false;">


Why are you returning false? It's not as if you can cancel loading.

[snip]

> <tr align="center" valign="middle">
> <td class="white_link"><a href="#"
> onClick="PreviousImage();">Previous</a></td>
> <td class="white_link"><a href="#"
> onClick="NextImage();">Next</a></td>


You should cancel the click events after calling the functions.

[snipped last bit of HTML]

> So, I though that by using the onLoad function for body I could set
> the correct image from the list (which is the same as the list on the
> thumbnail page, maybe uselessly?) by using image_number =
> opener.pImageNumber in the ActualImage function executed within
> onLoad, but is simply does not work.
>
> Do you have any idea what I am doing wrong? I thought that by using
> opener keyword and image_number = opener.pImageNumber I would be able
> to find out what value was used for running the show_image (
> pImageNumber) on the main page.


What you're attempting should work fine, but check the show_image()
function. At no point do you actually change the pImageNumber variable.

Hope that helps,
Mike

--
Michael Winter
http://www.velocityreviews.com/forums/(E-Mail Removed)d (replace ".invalid" with ".uk" to reply)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
not all values have corresponding parent values Jim in Arizona ASP .Net 4 08-23-2005 11:29 PM
What does sender.Parent.Parent.Cells() reference? Frustrating... Roy ASP .Net 2 02-11-2005 09:00 PM
Repeater- Accessing the parent row values from a child. si7ikon ASP .Net 0 12-03-2003 09:13 PM
Repeater- Accessing the parent row values from a child. si7ikon ASP .Net 0 12-03-2003 03:04 PM



Advertisments