Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

<a href> that goes nowhere


  • This topic is locked This topic is locked
8 replies to this topic

#1 Ronin

Ronin

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 302 posts

Posted 26 April 2007 - 06:44 AM

I have to use onMouseHover and MouseOver functions in a href but when the user clicks on the link it reloads the page. How can I make this link go nowhere (and do nothing)?

Also, take a look at my other thread: http://forum.codecal....html#post18209
  • 0

#2 WillB

WillB

    CC Regular

  • Just Joined
  • PipPipPip
  • 43 posts

Posted 26 April 2007 - 11:45 AM

I have to use onMouseHover and MouseOver functions in a href but when the user clicks on the link it reloads the page. How can I make this link go nowhere (and do nothing)?

Also, take a look at my other thread: http://forum.codecal....html#post18209


First off, I have trouble understanding what you are trying to accomplish...

You are using the <a href> justfor the onMouseHover and MouseOver functions?

Why do you have to use <a href>?
  • 0

#3 xtraze

xtraze

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 872 posts

Posted 27 April 2007 - 08:05 AM

Try it like this
<a href="#"........></a>

Wish you good luck, still I cannot understand what you want complete.
  • 0

#4 Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guest

Posted 27 April 2007 - 01:46 PM

If you use # it will reload the page. Do :


<a href="JavaScript:void()" ...>


To do nothing.

WillB - I don't think there is another way to do it is there?
  • 0

#5 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 27 April 2007 - 06:30 PM

Why would you want a link that does nothing? Curious...
  • 0

#6 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 28 April 2007 - 12:08 PM

I can think of one example, and one of our members John ran into. If you wanted a drop-down menu that the top link didn't do anything (like the Tutorials link here) but you still wanted the menus below to show. That is the only reason I can think of. Are you doing something like this Ronin?
  • 0

#7 xtraze

xtraze

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 872 posts

Posted 29 April 2007 - 08:24 AM

Maybe he has some problems with some CSS matters
maybe he wants the style given to Links applied to normal text.

If he did explain, we can easily get a solution.
  • 0

#8 WillB

WillB

    CC Regular

  • Just Joined
  • PipPipPip
  • 43 posts

Posted 30 April 2007 - 01:27 PM

When an anchor tag is used only for JavaScript functionality, an href attribute is still required. It's a link, after all.

This post shows how to keep the browser from visibly reacting when the link is clicked — the browser won't go anywhere, won't reload the page, nothing.

Putting this attribute into the anchor tag will solve most requirements.
onclick="return false"

If an onclick attribute is already being used in the anchor tag, appending "; return false" (without the quotes) to the attribute's value might work. Appending the return value is required because only one onclick attribute may be present in any one anchor tag.

However, if an onclick attribute is already being used and appending "; return false" to the attribute's value does not work (if it must return the true, for example, or the return value is determined by a function call), then the href attribute's value might be changed to something like this:
href="javascript:function Z(){Z=''}Z()"

The above is not very elegant, but it works with all browsers I've tested (Firefox, IE, Opera, Netscape 7+, all on XP).

To keep non-JavaScript browsers from following a link, the href attribute's value can be replaced with the "not very elegant" solution above (tested only with Firefox on XP) or replaced with an octothorpe character.
href="#"

The above will cause some non-JavaScript browsers to reload the page when the link is clicked. Others will just ignore the link.


Commented From = "http://www.willmaster.com/blog/javascript/How_to_Make_a_Link_that_Does_Nothing.html"


I guess you do use <a href> and Javascript together... If he is trying to get just the effects of the mouse over...
  • 1

#9 Ronin

Ronin

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 302 posts

Posted 01 May 2007 - 03:51 AM

Yup, I just want the onMouseOver effects. The onclick="return false" works. Thanks for all of your help.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download