Welcome to WebmasterWorld Guest from 54.146.246.4

Forum Moderators: incrediBILL

Message Too Old, No Replies

disable href, how?

use style of <a>, not its properties

     

mongoloid001

4:51 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



I want to display a link that doesn't use the href property, how do I go about to disable it. The following doesn't work in IE6:

<a href="" onclick="javascript:doBlahBlah()">

----- From MSDN site -----
If HREF is present but is blank (in other words HREF="" OR HREF=), executing the link could possibly display the directory containing the current page, or it could generate an error depending on other elements on the web page and the server environment.
--------------------------

smokin

4:53 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



<a href="#" Onclick="dosomething">link text</a>

will work

MonkeeSage

6:07 pm on Jul 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also do:

<a href="BlahBlah" onclick="javascript:doBlahBlah(); return false;">

The "return false;" tells the browser (in effect) "oh, nevermind, the user didn't really click the link." Your onclick will still fire correctly though. :)

The only real advantage this would have over just using a "#" as the href is that when the link is clicked it will not append a "#" to the URL displayed to the user in the URL bar.

Jordan

[edited by: korkus2000 at 5:57 pm (utc) on July 29, 2003]
[edit reason] No Sigs Please [/edit]

choster

6:41 pm on Jul 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="javascript:void(0);" onClick="....">

BTW onClick is an event handler, so you should not include the
'javascript:' pseudo-protocol.

mongoloid001

9:54 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



Thanks for the replies, they all work fairly well! However, I have a question for the following comment:

BTW onClick is an event handler, so you should not include the 'javascript:' pseudo-protocol.

what does[typo] it mean exactly? I think the browser is smart enough to ignore it, but I thought it would be a better practise to put javascript in front. Can someone clarify?

Thanks!

MonkeeSage

1:32 am on Jul 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



javascript: is a pseudo-protocol like about: or cache:, you don't need it if you are just calling functions that are already defined in a
<script>
tag with a proper
type
attribute. You are correct in thinking that it doesn't hurt anything to have it in there, though, it just isn't necessary. :)

Jordan

[edited by: korkus2000 at 5:57 pm (utc) on July 29, 2003]
[edit reason] No Sigs Please [/edit]

frank_stahl

2:20 pm on Jul 29, 2003 (gmt 0)

10+ Year Member



I always use

<a href="JavaScript:;" onclick="...">

which works just fine.

garann

5:35 pm on Jul 29, 2003 (gmt 0)

10+ Year Member



The only real advantage this would have over just using a "#" as the href is that when the link is clicked it will not append a "#" to the URL displayed to the user in the URL bar.

Actually, there's a big advantage in that people who have JavaScript turned off can still follow the link, presuming you've put a real path in the HREF. And I think I've read in these forums that this method also allows search engine spiders to follow the links. Right?

MonkeeSage

5:52 pm on Jul 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



garann:

Interesting! Never even though of that aspect of the problem. So I guess pragmatically and asthetically, including a valid path in the href and then canceling the click event is the best way to go about solving it. Mabye use the base href as the link href if it is otherwise unneeded?

Jordan

[edited by: korkus2000 at 5:57 pm (utc) on July 29, 2003]
[edit reason] No Sigs Please [/edit]

dancedevils

8:48 pm on Aug 3, 2003 (gmt 0)

10+ Year Member



There is a nice easy way where you set the link target as a '#'.

<a href="#">Example</a>

This means the link does not move you from the location where you are at the present and text 'Example' appears as a link.

To go more advanced you could do things like change the cursor style so it does not change i.e.

<a href="#" style="cursor: default;">Example</a>

Now when you move the mouse ove the text 'Example' it appears as a link but the mouse cursor stays the same as well! I hope this helps you.

Bon Bon

[edited by: korkus2000 at 1:59 pm (utc) on Oct. 18, 2003]

gph

10:12 pm on Aug 3, 2003 (gmt 0)

10+ Year Member



You can use just about any page element to act like a link.

<span class="link" onmouseover="this.className='link-over'" onmouseout="this.className='link'" onclick="go()">text</span>

.link {
color: blue;
}

.link-over {
color: yellow;
}

.link, .link-over {
cursor: pointer;
cursor: hand;
}