Forum Moderators: open
I am trying to have links change color when the mouse hovers over them. I am using CSS and it works fine except for the links that I am using javascript.
I use javascript links because I want some of the links to open in a new browser window of a certain size. Is there any way to add the onMouseOver and onMouseOut to the following link so that when I hover over it the font color changes?
<a href="javascript:;" onClick="MM_openBrWindow('http://www.domain.com','','scrollbars=yes,resizable=yes,width=545,height=300')">
Thanks in advance for the help.
Randy
<a href="javascript:function()">
or
<a href="#" onClick="function()">
In fact, I often use a variant of the second one so users without javascript still get the new page.
<a href="newpage.html" onClick="function();return false;">
The return false; will keep the original page from changing for people who do have javascript working.
However, something in your HTML or your CSS is probably a bit off -- There's no reason the hover behavior shouldn't work on a js link. Is the anchor tag properly closed?
I am not that experienced with Javascript. Can you show me an example of the way you set it up? How did you declare that function before you called it in the html link?
I am not that experienced with Javascript. Can you show me an example of the way you set it up?
The code I placed in that post essentially is the way I set it up, except that I used the expression function() instead of writing out the whole thing. I wanted to emphasize the differences between the two ways of coding and not have the visual distraction of all those parameters.
How did you declare that function before you called it in the html link?
I use an external .js file, but you could just as well define it in the <head> within a <script> element. Or, (wastefully, if you need it more than once) you can define the function right in the anchor element the way DreamWeaver did for you. Here is the way I would go about it, assuming that "url" is the address to load in the new window, and "winName" is the name of the new window object. You could also make any of the window parameters, including the size or position, into a variable. But I kept the following examples to just the basics.
IN THE HEAD SECTION OR EXTERNAL JS FILE
function popWin(url,winName) {
window.open(url,winName,'scrollbars=yes,resizable=yes,width=545,height=300')
}
IN THE HTML BODY
<a href="http://example.com/page.html" onClick="popWin('http://example.com/page.html','window1');return false;">Link Text</a>