Show image with link based on first directory with Javascript
Posted
by Nestorete
on Stack Overflow
See other posts from Stack Overflow
or by Nestorete
Published on 2010-03-07T19:07:10Z
Indexed on
2010/03/08
9:06 UTC
Read the original article
Hit count: 380
Hi, i need some help please,
i want to show an image on my Page depending of the first directory of the URL.
Example:
In Any of this URLs will show the image1.jpg
- www.mysite.com/audio/amplifiers/400wats.html
- www.mysite.com/audio/
- www.mysite.com/audio/amplifiers/
In any of this others will show the image2.jpg
- www.mysite.com/video/spots/40wats.html
- www.mysite.com/video/amplifiers/400wats.html
- www.mysite.com/video/lighting/laser.html
- www.mysite.com/video/laser/
At the moment i can show the image only if the url is only the first directory, bu no in the internal directory or documents.
This is the script that i'm using right now:
<script type="text/javascript">
switch (location.pathname)
{
case "/audio/":
document.write("From Web<BR>")
break
case "/video/":
document.write('<A HREF="slides.htm" target="_blank"><IMG SRC="/adman/banners/joinvip.gif" WIDTH=728 HEIGHT=90 BORDER=0></A>')
break
default:
document.write('<A HREF="http://www.apple.com" target="_blank"><IMG SRC="http://www.amd.com/us-en/assets/content_type/DownloadableAssets/NEW_PIB_728x90.gif" WIDTH=728 HEIGHT=90 BORDER=0></A>')
break
}
</script>
Thank you
© Stack Overflow or respective owner