-
[images src javascript]
Bonjour,
j'utilise ce code javascript pour changer une image. Ce code fonctionne cpdt je suis oblig� d'utiliser des url absolues, comment puis-je faire pour utiliser des url relatives ?
<SCRIPT language="JavaScript">
var img1 = 'http://localhost:9080/images/Exp.gif';
var img2 = 'http://localhost:9080/images/NoExp.gif';
function _ChangeImg(idImg)
{
((document.images[idImg].src==img1) ? (document.images[idImg].src=img2):(document.images[idImg].src=img1));
}
</SCRIPT>
Quelqu'un a une id�e ?
-
salut
tu peux tr�s bien faire var im1='../image.gif'
au besoin fais un alert images[IdImg].src pour savoir exactement comment le chemin de l'image est format�e
@+
-
En effet , c'est ce que j'ai fais :
<SCRIPT language="JavaScript">
var img1 = 'http://localhost:9080/images/Exp.gif';
var img2 = 'http://localhost:9080/images/NoExp.gif';
function _ChangeImg(idImg)
{
alert('document.images[idImg].src = ' + document.images[idImg].src);
((document.images[idImg].src==img1) ? (document.images[idImg].src=img2):(document.images[idImg].src=img1));
alert('document.images[idImg].src = ' + document.images[idImg].src);
}
</SCRIPT>
Resultat :
document.images[idImg].src = 'http://localhost:9080/images/Exp.gif'
-
ce que je te proposais est de remplacer l'url absolute par l'url relative...
-
Cela ne fonctionne pas d'ou ma question !
-
le code est-il dans la page, ou dans un fichier.js ?
-
Dans la page pour l'instant !
Parcontre j'ai essaye ce code et cela focntionne :
function _ChangeImg(id,idImg)
{
if (document.getElementById(idImg).alt=="Open")
{
document.getElementById(idImg).src = img2;
document.getElementById(idImg).alt = "Close";
}
else
{
document.getElementById(idImg).src = img1;
document.getElementById(idImg).alt = "Open";
}
}
-
oki, parfeit...
surtout, n'oublie pas le tag :resolu: