PDA

View Full Version : Trouble with function not receving params in FF



changemystrings
07-26-2008, 02:48 AM
Hi all - the code below is designed to attach an onmouseover event for all links on a page which calls a function that updates the status bar to the link title. This works great in IE, but I can't for the life of me get it to work properly in FF... I believe it's the way I'm generating the onmouseover event handler, but I'm not sure how else to go about it.... Thanks.


<html>
<head>
<script type="text/javascript">
function getStatus(obj)
{
var newStatus = obj.title;
window.status = newStatus;
return true
}


function clearStatus()
{
window.status = ' ';
}


function addLinkMouseEvents()
{
var d = document.getElementsByTagName('a');
for(i=0; i < d.length; i++)
{
var currAnch = d[i];
currAnch.onmouseover = function(){getStatus(this); return true;};
currAnch.onmouseout = function(){clearStatus();};

}

}
</script>
</head>
<body onload="addLinkMouseEvents();">
<a href="#" id="link" title="link1">Link text</a>
<a href="#" id="Link2" title="link2">Link2 Text</a>
</body>
</html>

Dal
07-26-2008, 02:58 AM
I would advise to add the window.onload = initialfunc() then add to that function addLinkMouseEvents(); instead of in the body tag.

Im not too hot on mouse event triggers so Im confussed about the currAnch.onmouseover method but Im sure that the document.addEventListener method is best for FF and the document.attachEvent is for IE.

Hope this helps.


//...
var d = document.getElementsByTagName('a');
for(i=0; i < d.length; i++)
{
var currAnch = d[i];

document.addEventListener("mouseover", getStatus(this), true); //double check if this is mouseover or onmouseover I know its a little different for EventListener
document.attachEvent("onmouseover", getStatus(this));
//...


Kind regards
Dal

jscheuer1
07-26-2008, 04:10 AM
In modern FF (I'm testing in FF 3), you cannot change the status bar onmouseover of a link. Now, there are various advanced options for FF as regards javascript. If these are set favorably, you can change the status onmouseover of other elements. So, you could change (either by hard coding it that way, or by action carried out via javascript at some opportune time in the process) the link to an ordinary a tag with no href attribute and add an onclick event to it to execute the page change onclick. Then, if the advanced options are set favorably, the status bar change would work.

This seems to me to be not worth the trouble. You cannot control the advanced javascript settings of a given user, and the default is to allow absolutely no changes to the status bar.

But you may want to consider this approach:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<noscript>
<a href="http://www.google.com/" title="link1">Link text</a>
<a href="http://www.dynamicdrive.com/" title="link2">Link2 Text</a>
</noscript>
<a href="javascript:link1" onclick="window.location='http://www.google.com/';return false;" id="link" title="link1">Link text</a>
<a href="javascript:link2" onclick="window.location='http://www.dynamicdrive.com/';return false;" id="link2" title="link2">Link2 Text</a>
</body>
</html>

Which actually takes advantage of the default behavior of any browser with status bar enabled to show the href attribute.

Dal
07-26-2008, 04:34 AM
I would look into who actually looks at the status bar anyway and cut your loses if its just a superficial method which really doesnt require the user to read it. I didnt realise that FF doesnt support the status description for links but then again it makes perfect sense if you want to check where your going, this is the ONLY time I would ever look down there :D Its too close to my M$ start logo and it burns me up in side everytime I see M$ :D Hence FF.

Try using floating DIVs like tool tips if you want to tell the user something attached to a link. Just a suggestion.

Thanks
Dal

changemystrings
07-27-2008, 12:53 AM
I appreciate everyone's prompt feedback. I needed to create this script for an affiliate site - in some instances potential buyers are turned off if they see an affiliate style link in the status bar. I'm using a "launch" page for these links regardless for BI purposes but wanted to display a call to action in the status bar for increased conversion ratio. I was unaware that FF3 would prevent modification of the status bar for link events (this is probably a good thing anyway). Again, thanks for your help... Cheers!