PDA

View Full Version : How to turn off SwapImage based on URL


CyberScout
11-27-2002, 07:58 PM
Ok, I have this page here

http://www.hfs.psu.edu/includes/nav_ocs.stm

and as you can see the last button "contact us" is being changed by the URL. However, when you mouseOver that button it still has the mouseOver changing it to another image.

Using the script I already in place to change document.contactus.src based on the URL, How do I change the swapImage to the image "Nav_Contact3.gif" or atleast how do I tell it to NOT have a mouse over if the URL is equal to http://www.hfs.psu.edu/includes/nav_ocs.stm?

Any help on this would be GREATLY appreciated.

Thanks in advance
CyberScout

chrismiceli
11-27-2002, 11:09 PM
function checkimg() {
if (top.location.src == http://www.hfs.psu.edu/includes/nav_ocs.stm?) {
}
else {
//code for when not equal to url above;
}
<img src="contact" onMouseOver="checkimg()">

am i close?

glenngv
11-28-2002, 09:08 AM
Well, not close :D
You got 2 errors:
there is no src property for location object.
the url should be enclosed in quotes

CyberScout, I think that history.current is supported only by Netscape. But that is not the correct way to get the current url.

<script language="JavaScript" type="text/JavaScript">
<!--
if (location.href == 'http://www.hfs.psu.edu/includes/nav_ocs.stm') {
document.contactus.src = "../includes/Lnav_ocs/Nav_Contact3.gif";
}
//-->
</script>

I highlighted the == operator because you only use = in doing the comparison.

CyberScout
12-02-2002, 02:49 PM
Glenn,

That does seem to be much smoother. I incorporated that into my page at http://www.hfs.psu.edu/includes/nav_ocs.stm

Now, I have the problem though of changing the second image. The rollover still comes up and makes the text flush to the left.

Thanks for your help. Any thoughts on chaning the rollover image would be great.

CyberScout

glenngv
12-03-2002, 12:54 AM
That page has still the old code. I can't find the new one.

CyberScout
12-03-2002, 01:49 PM
The script you gave me:

<script language="JavaScript" type="text/JavaScript">
<!--
if (location.href == 'http://www.hfs.psu.edu/includes/nav_ocs.stm') {
document.contactus.src = "../includes/Lnav_ocs/Nav_Contact3.gif";
}
//-->
</script>

Is placed at the very bottom of the page:
http://www.hfs.psu.edu/includes/nav_ocs.stm

When viewing source it is the last thing on there. Am I explaining my second probably clearly?

I just read over it again and it doesn't read very well.

As always, thanks in advance
CyberScout

glenngv
12-04-2002, 01:10 AM
That's because you change the image onmouseover to Nav_Contact2.gif
Is that the correct image?

CyberScout
12-04-2002, 01:48 PM
Yes, that is the image that needs to be changed.

Right now the script is changing the image "Nav_Contact.gif" and I need one that will do that, but that will also change "Nav_Contact2.gif"

Basically making both the first image "Nav_Contact.gif" and the second (rollover) image "Nav_Contact2.gif" to "Nav_Contact3.gif"

Thanks for all your help so far Glenn
CyberScout

glenngv
12-05-2002, 01:06 AM
give that anchor link a name:

<a name="contactlink" href="http://www.hfs.psu.edu/contract/contact.stm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contactus','','../includes/Lnav_ocs/Nav_Contact2.gif',0)"><img src="../includes/Lnav_ocs/Nav_Contact.gif" name="contactus" width="152" height="17" border="0"></a>


then in your script:

<script language="JavaScript" type="text/JavaScript">
<!--
if (location.href == 'http://www.hfs.psu.edu/includes/nav_ocs.stm') {
document.contactus.src = "../includes/Lnav_ocs/Nav_Contact3.gif";
document.links["contactlink"].onmouseover=null;
document.links["contactlink"].onmouseout=null;
}
//-->
</script>

you can also use:
document.links[document.links.length-1].onmouseover=null;
document.links[document.links.length-1].onmouseout=null;

that is, if the link is the last link in the page.
but it's better to reference the link by name so that it will always work even if you add another links below it.

CyberScout
12-05-2002, 03:32 PM
Hmmm ... I pasted the script just as you have it and I got an error.

Line: 69
Char: 1
Error: 'document.links.contactlink' is null or not an object
Code: 0

I tried some different ways to right it, but with luck.

CyberScout
12-06-2002, 06:30 PM
Still nothing ... on this.

I am still getting that same error. It is almost like it can't tell what document.link is.

Anyway, if anyone has anything thoughts, it would be much appreciated.

-CyberScout

glenngv
12-09-2002, 01:01 AM
you don't have <html> and <body> tags required to make it a HTML document.

<html>
<head>
<title>title</title>
</head>
<body>
body content goes here...
</body>
</html>