Sijun Forums Forum Index
Log in to check your private messages
My Profile Search Who's Online Member List FAQ Register Login Sijun Forums Forum Index

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
   Sijun Forums Forum Index >> Random Musings
View previous topic :: View next topic  
Author   Topic : "Can anyone help me with Javascript?"
Awetopsy
member


Member #
Joined: 04 Oct 2000
Posts: 3028
Location: Kelowna

PostPosted: Wed May 05, 2004 1:28 pm     Reply with quote
Hey all.. wondering if any of you know anything about Javascript. Ive run into an impass.

Here is what Im trying to do:

I have a few thumbnail images in a folder that I have rotating randomly on each refresh or click.
I have the full size images in another folder which I want to open in a new window when the corresponding image is clicked in the random image window. (is that clear?)

Basically I want the random image window to advance to the next random image but also bring up the full size image in the new window. For instance if a person loads my page and sees "image1_thumbnail" in the random image view area then when they click on it a new window appears with the "image1_fullsize", and the random image view area changes to the next random image.

here is my code:

in the "<head>" tag

Quote:


var rand1 = 0;
var useRand = 0;
var globalWindow;
var globalBrowserName = navigator.appName;
var globalBrowserVersion = parseInt(navigator.appVersion);

images = new Array;
images[1] = new Image();
images[1].src = "iom/boss_01.jpg";
images[2] = new Image();
images[2].src = "iom/franky.jpg";
images[3] = new Image();
images[3].src = "iom/catearcher.jpg";
images[4] = new Image();
images[4].src = "iom/llama.jpg";
images[5] = new Image();
images[5].src = "iom/jester.jpg";

function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}

function openWindow(imageName, winWidth, winHeight) {

if ( globalBrowserName == "Netscape" && globalBrowserVersion > 2) {
if ( globalWindow ) {
if ( globalWindow.document ) {
globalWindow.close();
}
}
} else {
if ( globalBrowserName == "Microsoft Internet Explorer" && globalBrowserVersion > 2) {
if ( globalWindow ) {
globalWindow.close();
}
}
}

globalWindow = window.open("", "PopUp", "width=" + (winWidth + 30) + ",height=" + (winHeight + 50) + " ,scrollbars=0,toolbar=0,resizable=1,location=0,men

ubar=0");

globalWindow.document.writeln('<HTML>');
globalWindow.document.writeln('<HEAD><!--BASE HREF="http://www.noelnissen.com/"--></HEAD>');
globalWindow.document.writeln('<BODY BGCOLOR="#336699" link="7194B8" vlink="7194B8" alink="7194B8" text="A3BAD1">');
globalWindow.document.writeln('<CENTER>\n');
globalWindow.document.writeln('<A HREF="java script:self.close()">close this window</A><BR>');
globalWindow.document.writeln('<IMG SRC="gallery/' + imageName + '" WIDTH=' + winWidth + ' HEIGHT=' + winHeight + '><BR>');
globalWindow.document.writeln('</CENTER>\n');
globalWindow.document.writeln('</BODY>');
globalWindow.document.writeln('</HTML>');

return;
}
//-->
</script>




in the <body> tag Ive put:

Quote:


OnLoad="swapPic()"



and then inside the body Ive got:

Quote:


<a onClick="swapPic();" href="java script: openWindow()"><img name="randimg" src=""></a><br>



It does open the new window for me but it wont show any graphics.. I think its because It cant tell which random image is currently being displayed.. but I have no idea how to do that.

Am I going about this the worng way? Any help would be greatly appreciated.

thanx.
Back to top
View user's profile Send private message
DJorgensen
member


Member #
Joined: 26 Jun 2003
Posts: 147
Location: Edmonton, Canada

PostPosted: Wed May 05, 2004 11:54 pm     Reply with quote
Well taking a quick look, I think that the problem may be inside the body where you call the openWindow() method. You never passed any arguments into the method however.

In your code, the openWindow method accepts three arguments:
imageName, winWidth, winHeight

Passing the arguments as null, the method can still run, but it will not write the code for the image I believe.

As well on a side note, I would suggest that you start your array of images at 0 instead of 1. This will get rid of the need to add and subtract 1 throughout.

I am not 100% sure though. It is just what I would try first.
My personal experience with javascript is limited to what I have taught myself. In University, all we ever do for the first year is Java, yet they somehow avoid teaching us anything that would be useful or practica.

I hope this helps a little.
DJorgensen
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Ian Jones
member


Member #
Joined: 01 Oct 2001
Posts: 1114
Location: Brisbane, QLD, Australia.

PostPosted: Thu May 06, 2004 5:51 am     Reply with quote
"In University, all we ever do for the first year is Java, yet they somehow avoid teaching us anything that would be useful or practical. "

Seems to be a worldwide trend. Happens over here aswell.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Sijun Forums Forum Index -> Random Musings All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Powered by phpBB © 2005 phpBB Group