PDA

View Full Version : JavaScript - IE/MAC will not display.



mejust
05-15-2006, 11:19 AM
Hi all....

The following Javascript does not seem to work using IE on a MAC. The images do not display. Seems to work OK using Safari and all browsers on a PC.

The script creates a slideshow of images.

Any suggestions? Much appreciated!....

<script type="text/javascript"><!--
function GotoPic(Num){
location.href=location.pathname+'?'+Num;
}

N=-1;Picture=new Array;
N++;Picture[N]="imagename.jpg";
N++;Picture[N]="imagename2.jpg";
N++;Picture[N]="imagename3.jpg";
N++;Picture[N]="imagename4.jpg";

var ThisPic;
var PrevPic;
var NextPic;
var ShowPrev;
var ShowNext;

if (location.search){
ThisPic=location.search.substring(1)*1;
}else{
ThisPic=0;
}

NextPic=ThisPic+1;ShowNext=(NextPic>(Picture.length-1)?false:true);
PrevPic=ThisPic-1;ShowPrev=(PrevPic<0?false:true);

if (ShowPrev){
document.writeln('<a href="javascript:GotoPic(PrevPic)"><img src="navigation/previous.jpg" width="75" height="23" border="0"></a><img src="navigation/blank.jpg"> ');
}
if (ShowNext){
document.writeln('<a href="javascript:GotoPic(NextPic)"><img src="navigation/next.jpg" width="37" height="23" border="0"></a> ');
}
document.write('</P><img src="'+Picture[ThisPic]+'">');
// -</script>

Twey
05-15-2006, 01:09 PM
Let's clean up your code. Try:
<script type="text/javascript">
function GotoPic(Num){
return location.pathname + '?' + Num;
}

var Picture = new Array;
Picture.push("imagename.jpg");
Picture.push("imagename2.jpg");
Picture.push("imagename3.jpg");
Picture.push("imagename4.jpg");

var ThisPic,
PrevPic,
NextPic,
ShowPrev,
ShowNext;

if (location.search)
ThisPic = location.search.substring(1) * 1;
else
ThisPic = 0;

NextPic = ThisPic + 1;
ShowNext = NextPic > (Picture.length - 1);

PrevPic = ThisPic - 1;
ShowPrev = PrevPic < 0;

if (ShowPrev)
document.writeln('<a href="javascript:GotoPic(PrevPic);"><img src="navigation/previous.jpg" width="75" height="23" border="0"></a><img src="navigation/blank.jpg"> ');

if (ShowNext)
document.writeln('<a href="javascript:GotoPic(NextPic)"><img src="navigation/next.jpg" width="37" height="23" border="0"></a> ');

document.write('</P><img src="'+Picture[ThisPic]+'">');

</script>I haven't made any major changes here, just cleaned up your code a little to avoid some bad practices. However, the route you've taken to accomplish this slideshow is a rather circuitous and clunky one. Is there any particular reason you've done it this way, or may I clean up your method as well?

mejust
05-15-2006, 04:28 PM
Thank you for your reply.

I tested your version (on PC/FireFox) but could not get it to work (also still does not display using IE/MAC). The 1st image displays the 'previous' option but not the 'next option'.

I found the orginal script after asking on various forums for something suited to my needs. I do not really know JavaScript.

I will Private Msg you the actual site running this script if you feel it would help?

Many thanks! :-)

Twey
05-15-2006, 04:45 PM
It would, yes. I will need you to test it with IE/Mac, though, since I do not have any version of IE at my disposal.

mejust
05-15-2006, 05:13 PM
A live version of the site can be found here (in case this helps):

edited-

And here is a page (one of many) using the script itself:

-edited--

mejust
05-16-2006, 09:19 AM
Feel free to change the method :-)
Really appreciate your help - havent had any responses from various other forums... so a bit stuck now!

mejust
05-17-2006, 03:22 PM
This issue has now been resolved...

http://forums.htmlcenter.com/showthread.php?p=9946

Thanks for all your help.