homepage Welcome to WebmasterWorld Guest from 54.166.128.254
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
disable href, how?
use style of <a>, not its properties
mongoloid001

10+ Year Member



 
Msg#: 5773 posted 4:51 pm on Jul 28, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 5773 posted 4:53 pm on Jul 28, 2003 (gmt 0)

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

will work

MonkeeSage

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 5773 posted 6:07 pm on Jul 28, 2003 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 5773 posted 6:41 pm on Jul 28, 2003 (gmt 0)

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

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

mongoloid001

10+ Year Member



 
Msg#: 5773 posted 9:54 pm on Jul 28, 2003 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 5773 posted 1:32 am on Jul 29, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 5773 posted 2:20 pm on Jul 29, 2003 (gmt 0)

I always use

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

which works just fine.

garann

10+ Year Member



 
Msg#: 5773 posted 5:35 pm on Jul 29, 2003 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 5773 posted 5:52 pm on Jul 29, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 5773 posted 8:48 pm on Aug 3, 2003 (gmt 0)

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+ Year Member



 
Msg#: 5773 posted 10:12 pm on Aug 3, 2003 (gmt 0)

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;
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved