onMouseover/onMouseout

They have: 10 posts

Joined: Aug 1999

I love this place...

I use this a lot:
<a href="page.htm" onMouseover="window.status='This is the message.'; return true" onMouseout="window.status=' '; return true">

Is there any way to call these in a function so that I don't have to type all that out for every link?

- Botch

They have: 5,633 posts

Joined: Jan 1970

There is a way of saving a bit of typing, add this script to the <head> section:

<script language="JavaScript">

var text=" ";

function onlink (text)
{
window.status=text;
}
function offlink (text)
{
window.status=text;
}

</script>

You can call the functions whatever, I use onlink and offlink for some reason.

Then the onMouseover is shortened to:

<a href="page.html" onMouseover="onlink('Message goes here');return true" onMouseout="offlink('');return true">

The code is still quite long, but shorter than the original. To save your fingers even more you could have the script as an external .js file

[This message has been edited by tomworld (edited 30 November 1999).]

[This message has been edited by tomworld (edited 30 November 1999).]

They have: 10 posts

Joined: Aug 1999

Thanks! As a supplemental question, can onMouseover and onMouseout be used in a function? In other words, the link would call the function with two variables (the URL and the onMouseover string), and the function would do the rest?

- Botch

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.