开发者

Can I disable an address link in HTML?

I have t开发者_StackOverflowhe following:

<a href="/Product/Overview">Overview</a>
<a href="/Product/Review">Review</a>

When I am on the overview page I want to make it so that clicking the overview address link does nothing. Something like disable for a button. Is this possible for an address link?


This should do it:

<a href="/Product/Overview" onclick="return false;">Overview</a>

Of interest may also be nofollow:

<a href="/Product/Overview" onclick="return false;" rel="nofollow">Overview</a>


The easiest way to disable a link is probably to remove the href value.

If you are rendering this from MVC, simply don't include the <a> tag.

It's a little unclear what is best for what you're trying to do.


Add 'return false' to prevent linking:

<a href="/Product/Overview" onclick="return false">Overview</a>


Just use a # sign in the href like so: <a href="#">Overview</a>


You could do this with a layer of javascript on top of each page: your JS script would run and check all the links on the page -- if the link is the same as the page you are on then simply "hijack" the anchor by adding an onclick event which does nothing and doesn't bubble up the event. This was you still pump out from your server side all the links -- and the script would be the same for all the pages, thus allowing it to be cached by the browser and only loaded once (assuming you place it in an external .js file).


You can try <a class="inactive" href="#">Overview</a> and give it some CSS to show it's a different type of link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜