-1

I would like to disable a link in my drupal 7. And i have no idea how to do that. Is there a module for it. This particular link (https:// xx.xxx.xx.xxx/dev/node) is when i purposely put the link directly on the URL tab (when logged in) and not navigate via any click. I don't have access to its HTML. I tried with the CSS given in this URL - How to disable a link using only CSS?

but it didn't work . Infact it won't work since the URL is nowhere to be seen. The page appears only when i manually enter the URL.

1 Answers1

0

Depending on what you mean by "disable", you can use JavaScript's onclick event and have it return false. That will "disable" the link, meaning, when you click the link, absolutely nothing happens. The return false statement will break the links default behavior, which is to redirect the user to whatever reference (href) is made.

Example: <a href="my/path" onclick="return false;">Click me and nothing happens!</a>

If you by "disable" mean, hide the element so that it's not interactable at all, you can use the CSS property visibility and set it to hidden.

Example: <a href="my/path" style="visibility: hidden !important;">No one can see me!</a>

The "!important" keyword basically just means that the CSS interpreter should prioritize that CSS rule over other rules. That way, you're almost positive that your CSS rule will be applied in all cases.

Instead of inline styling, you could of course use CSS classes etc. to apply the same CSS, which might come in handy if you have a few links, or other elements that you wish to "hide".

You could also look into CSS pointer events, which will basically be the "non-JavaScript" version of the same JavaScript solution that I provided earlier.

Martin
  • 2,326
  • 1
  • 12
  • 22