PDA

View Full Version : Change an image based on URL


CyberScout
11-27-2002, 03:04 PM
Ok, this should be pretty straight foward.

Basically, I have a server-side-include on my pages that houses the left side navigation. What I am trying to do is say.

If the URL is "http://blah.stm" then make

img src="duh.gif" (img src=duh2.gif)

The general idea is making an image change depending on what the url is.

Here is what I have so far, and this could VERY far off, but I did try.

<script language="JavaScript" type="text/JavaScript">
<!--
if (document.url = nav_ocs.stm') {
src='../includes/Lnav_ocs/Nav_Contact.gif' ('../includes/Lnav_ocs/Nav_Contact2.gif');
}
//-->
</script>

Thanks in advance
CyberScout

BrightNail
11-27-2002, 09:24 PM
not entirely sure what you want to do..

but why not use a switch statement and if the URL matches one of the cases,, the call a standard "image" switch function and pass it the appropriate parameters..

I'd also create an array of the images..

is it just "one" image that will change depending on the URL? are you using an image map?

you could also create two arrays..one for "expected" urls and one for their corresponding image....do a "for" loop, and run thru the array of URLS..if it finds a match,,then call the corresponding image array index.....ala..

var theseURL = new Array('aplace.com','another.com')

var theseImage = new Array ('image1.gif','image2.gif')

for(i=0;i<theseURL.length;i++){
if(document.URL.indexOF(theseURL[i])!=-1){
document.imageSwitch.src = theseImage[i]
}
}

remember, you have to put "imageSwitch"...for the name attribute of the image..

something like that..

Mr J
11-28-2002, 05:37 PM
In your nav page you could have something like ....




<a href="#null" onclick="parent.main.location='page2.htm'"><img name="pic" src="pic1.gif"></a>




And in the page that loads into the main frame


<script>

parent.navigation.pic.src="pic2.gif"

</script>

This would allow for the image to be change by the page that loads

glenngv
11-29-2002, 06:27 AM
cross-posted!
http://codingforums.com/showthread.php?s=&threadid=10575

FYI, you can search your previous posts by using the forum's search function. Search by username to see your previous posts.