Welcome to WebmasterWorld Guest from 54.163.166.22

Forum Moderators: incrediBILL

Message Too Old, No Replies

disable href, how?

use style of <a>, not its properties

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

Junior Member

10+ Year Member

joined:Mar 24, 2003
posts:56
votes: 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.
--------------------------

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

Junior Member

10+ Year Member

joined:July 3, 2002
posts:82
votes: 0


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

will work

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 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]

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Dec 17, 2001
posts:1262
votes: 0


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

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

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

Junior Member

10+ Year Member

joined:Mar 24, 2003
posts:56
votes: 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!

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 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]

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

New User

10+ Year Member

joined:June 4, 2003
posts:19
votes: 0


I always use

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

which works just fine.

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

Preferred Member

10+ Year Member

joined:Sept 4, 2002
posts:508
votes: 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?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 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]

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

New User

10+ Year Member

joined:Aug 3, 2003
posts:5
votes: 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:12 pm on Aug 3, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Jan 31, 2002
posts:285
votes: 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;
}

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members