CSS : Universally disable all hyperlink


This is article the power of CSS, for the uninitiated that will be cascading style sheets - generally this is what gives the site its style and graphical attributes however you can do quite a bit more than that, especially if you’re using CSS3….

I have used this before and it works Very well, the intended purposes, Let’s say, do you have a requirement to disable every single link on your website immediately - You could go through oil code and remove all the HTML tags, but that would take quite a bit of time, if your website has a CSS template then you can use this:

/* Disable pointer events on all anchor tags */
a {
    pointer-events: none;
    cursor: default
    color: gray; /* Optional: Change color to indicate the link is disabled */
    text-decoration: none; /* Optional: Remove underline to indicate the link is disabled */
}

/* Optional: Update styles to make disabled links more obvious */

a:hover {
    color: gray;
    text-decoration: none;
}

Then, if you wish to disable the text selection from within a browser, then you can also use the script, this will stop the user from highlighting text to copy and paste:

/* Disable text selection */
body {
    -webkit-user-select: none; /* Chrome, Safari, and Opera */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
    user-select: none; /* Standard syntax */
}

You will find CSS has its limitations and that’s if you wish to do enforce certain restrictions, as an example if wish to stop the copying completely, you can use this script in your HTML head tags

<script>
    document.addEventListener('copy', function(e) {
        e.preventDefault();
    });
</script>

If you wish to stop people right clicking, which is where they usually view your website source you can use this particular script:

/* Prevent right-click */
document.addEventListener('contextmenu', function(e) {
    e.preventDefault();
});
Previous Post Next Post

نموذج الاتصال