If you encourage people to use # and stop the usual behavior (which is to scroll to the top of the document), then someone will use the function’s return false value in the onclick event, which means:
Also, if you use javascript:void instead, you don’t have to return false on the click event. As we already said, void(0) is the smallest script that can evaluate to “undefined,” which means:
javascript:void
When you use JavaScript, the return result of the script that was run, if there is one, becomes the content of a new document that is shown in the browser. In JavaScript, the void operator makes the statement that comes after it return undefined, which stops this action from taking place.
Because a javascript: URL will usually take the browser to a plain text form of the result of running that JavaScript, you’d want to do this with the href of a link. If the result is not known, however, the browser stays on the same screen. You can write as little code as possible that evaluates to “undefined” and calls itself “void(0).”
However, javascript:void(0); breaks the Content Security Policy on HTTPS that is enabled for CSP. As an extra layer of data security, Content Security Policy (CSP) helps find and stop some types of attacks, like Cross-Site Scripting (XSS) and data injection attacks. Many companies depend on custom AI development services to create safe, scalable, and standards-compliant web apps as modern apps get more complicated. AI-powered development workflows help developers find security holes, improve CSP compliance, find the best ways to use JavaScript, and follow modern best practices for the front end without affecting performance or the user experience.
Modern web apps made by an AI software development company often follow strict security rules and code standards to make them run faster, be easier for everyone to use, and protect against security holes. Businesses can get help from an AI development company that knows how to make safe, scalable web apps that follow best practices for running JavaScript, following the Content Security Policy (CSP), and using modern frontend development.
These attacks can be used to steal data, change the look of a website, or spread malware.
href=”#”
To avoid breaking any laws, if you’re a normal religious developer, you might want to use href=”#” instead of javascript:void.
link=”#”Keep in mind that you can also return false directly in the element’s onclick attribute to get the same result:
It’s safer to use the password in case your user doesn’t have JavaScript turned on.
It’s easy to fix by adding this jQuery code to all the links in your page that have this value:
Keep in mind that you can also return false directly in the element’s onclick attribute to get the same result:
The conclusion and suggestions
If you need to be strict, quick, and raw, use javascript:void(0).
To be a standards follower, use href=”#” and stop the default event with JavaScript.



