473,513 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PROBLEM: window.open & accessing parent variables' values

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
Jul 23 '05 #1
1 3580
On 4 Apr 2004 21:56:57 -0700, Jiri Brada <br****@gsl.cz> 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
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8488
by: Michael Lee | last post by:
Does anyone know why the following function works in FireFox but not in IE6? function ShowTable() { clonedNode = document.getElementById("myTable").cloneNode(true); win = window.open(); win.document.body.appendChild(clonedNode); } I am trying to display a table with id="myTable" in a new window. IE6
2
9229
by: umashd | last post by:
Hi, I am doing a web based project for my graduation. I studied bit of java for backend processesing and javascript for the client. Here is the scenario. In the FORM, I use INPUT TYPE=text VALUE=" " NAME=cat, and a gif next to it. User will click on the icon to get a new window. In the new window, the user selects a value from the pull...
14
11021
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a window.open function? I would prefer not to create a separate HTML page. So far all I have is the basic var cwin =...
23
6366
by: Markus | last post by:
Hi, i have this problem: Sometimes, i can't reproduce, if i click on an small image on the website, the popup _AND_ an other Tab in firefox open. Here are the linkcode: <div align="center">
4
22159
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a description and a class_id (stored in the value attribute of each option). The user will then select a class from the drop-down list. What I want...
3
1410
by: krishna | last post by:
Below is the code. language = asp.net/vb.net private sub openW() sResult = sResult & "<script language=javascript> mywindow = window.open('http://localhost/mohsaic/default.aspx?tc=Client/Manage'); " sResult = sResult & "mywindow.parent.frames.location = 'http://localhost/treeview/treeview.aspx?m=c&pid=366826706'; "
3
6135
by: harikrishnan.kamalakannan | last post by:
Hi, When a open an asp page from a modal window through window.open, my session values of parent(the screen that invoked the modal window) are lost. Please this is urgent.
1
4264
by: jennyzest4u | last post by:
Hi, I 'm trying to access some fields in the parent window from a child window like this.. Here is my parent Jsp, which has the following script.. if (window.opener.parent.frames) { var tempDoc = window.opener.parent.frames.document; tempDoc.open();
2
3137
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early...
0
7273
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7545
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5707
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5105
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4763
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3256
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3246
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
480
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.