Click to See Complete Forum and Search --> : link to my .js file


turb
07-22-2003, 02:37 PM
I've got a little prob ...

my homepage (index.php) is on the server root but all my others php pages are in a folder call PHP. I alway use a JS file so i put all my javascript in and this file is on a folder call INCLUDE.

so i've got this on server :

INCLUDE
PHP
IMAGES
index.php

My prob is that when i link my .js file to index.php, if i've rollover button script, the way to the image files is "images/" ....

but this same rollover button script have to work with the others .php page, and the way to reach the image files is now "../images/".

Is there a way to set a variable so when i detect i'm on index.php, i'll use "images/" into my .js file and when i'm on the others pages, use "../images/" ?????

I know it's more a javascript question but i didn't know where to post my question ...

Thanx in advance

Steve

Timg
07-22-2003, 03:41 PM
A couple of thoughts...

Have a global js variable that set the prefix to the images folder.

somthing like this...

var prefix = "../";

function setImageSrcFiles(){
img1.src = prefix + "images/image.gif";
img2.src = prefix + "images/image.gif";
img3.src = prefix + "images/image.gif";
//etc...
}

Then on the index page onload call a function that sets the prefix to a blank string and call setImageSrcFiles().

Or you can determine where you are in the file system though the scripting language (both Java and ASP can do it - so I bet php can). Then use the values from your path to extrapolate where you need to go for the images. Probably a little more complex, but it should work very well (and if you did it correctly, you might never have to write the image folder path ever again).

Hope it helps.
Tim

Phil Karras
07-22-2003, 03:44 PM
You can use JS to check the URL and inside the URL look for index.php, if it finds that then use one way, otherwise use another way.


if(document.referrer.indexOf("/index") != -1) { // do this
.
}
else { // do this
}

Jona
07-22-2003, 03:44 PM
You could do it with JavaScript or PHP. Whichever you like. JavaScript would be something like this...


<script type="text/javascript">
<!--
var folder = "";
if(location.href.indexOf("/") == 3){
folder = "/images/";
} else {
folder = "../images/";
}
//-->
</script>


Of course, in your rollover functions, you'd have to use document.images[nameOfImage].src=folder+newSRC+".src" or something like that.

[J]ona