PDA

View Full Version : JSScript don't work in NN, but work in IE


no_hh
04-21-2004, 10:10 AM
Hi all!

I have a script which work fine in Internet Explorer but don't work in Netscape Navigator (I have NN4.7).
This script display some images (e.g. : 1.jpg and 2.jpg) , but in NN it does't display anything. Please give me any ideea !

Thks!

--
<html>
<head>
<script type="text/javascript">
var photos=new Array()
var which=0
photos[0]="1.jpg"
photos[1]="2.jpg"
var preloadedimages=new Array()
for (i=0;i<photos.length;i++){
preloadedimages[i]=new Image()
preloadedimages[i].src=photos[i]
}
function keeptrack(){
window.status="Imaginea "+(which+1)+" din "+photos.length
}
function backward(){
if (which>0){
which--
document.images.photoslider.src=photos[which]
keeptrack()
}
}
function forward(){
if (which<photos.length-1){
which++
document.images.photoslider.src=photos[which]
keeptrack()
}
}
</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td ><p align="left"><a href="#" onClick="backward();return false">Previous</a></td>
<td ><p align="right"><a href="#" onClick="forward();return false">Next</a></td>
</tr>
<tr>
<td width="100%" colspan="2" height="22"><center>
<script>
document.write('<img src="'+photos[0]+'" name="photoslider" border=0>')
</script>
</td>
</tr>
</table>

</body>
-------------

sad69
04-21-2004, 07:41 PM
That's because IE let's you do things that NN won't. NN follows the standards whereas IE follows some standards, and then also allows you to do things in a non-standard way.

You've not coded your script to the standard, and as a result, users with browsers other than IE won't be able to view your code properly. Then again, if you code your scripts to the standards, users with IE won't necessarily be able to view your code properly either!

I don't have NN installed on this machine, but here is the code as I think it should look like:

<script type="text/javascript">
var photos=new Array();
var which=0;
photos[0]="1.jpg";
photos[1]="2.jpg";
var preloadedimages=new Array();

for (i=0;i<photos.length;i++){
preloadedimages[i]=new Image();
preloadedimages[i].src=photos[i];
}

function keeptrack(){
window.status="Imaginea "+(which+1)+" din "+photos.length;
}

function backward(){
if (which>0){
which--;
document.images["photoslider"].src=photos[which];
keeptrack();
}
}

function forward(){
if (which<photos.length-1){
which++;
document.images["photoslider"].src=photos[which];
keeptrack();
}
}
</script>


Hopefully that works for you. If not, I can't remember with NN, but I'm sure there's a Javascript console that will tell you if there's an error with your Javascript. IE's got it in the bottom left corner of the status bar, so NN should have something similar.

So check that console to see what's wrong exactly. What may end up happening is that you'll have to have 2 separate scripts -- one for IE and one for NN -- and you'll have to use an if statement to determine what browser the user is using, and run the corresponding script. But hopefully coding to the standards will work for you.

Hope that helps,
Sadiq.

Choopernickel
04-21-2004, 09:49 PM
The javascript console in Netscape4 (and Mozilla flavors) can be accessed from the address bar by typing javascript:.

Mr J
04-21-2004, 09:54 PM
I thought NN was finished :confused:

liorean
04-21-2004, 10:29 PM
Nn4 is discontinued since years ago. Ns7 is the current Netscape browser - and I hear that Mozilla have decided on making 1.7 the next stable branch, from which Netscape will build ns7.2 (yes, they're back, but they're no longer going to do any real work, they'll just release a rebranded moz), taking over from the old stable branch, 1.4. The firefox developers had decided on basing the 1.0 release on 1.7, which is why they changed from the previously predicted 1.8 for a stable branch.

glenngv
04-22-2004, 03:25 AM
This script display some images (e.g. : 1.jpg and 2.jpg) , but in NN it does't display anything. Please give me any ideea !

Try putting document.close after the document.write statement.

<script type="text/javascript">
document.write('<img src="'+photos[0]+'" name="photoslider" />')
document.close();
</script>