sodcalculator

10 Tech How-To

JavaScript void0 Error? Causes & Fixes

Guide 10-17481 · Updated · Step by step

The “javascript:void(0)” error is not a real error message—it’s a browser behavior that appears when a link or script uses the void operator and something goes wrong, often leaving the page unresponsive or showing a blank screen. This article explains what javascript:void(0) actually does, why you might see it, and how to fix the underlying issues in your browser or code.

What Does javascript:void(0) Mean?

In JavaScript, void is an operator that evaluates an expression and then returns undefined. When used in a URL like javascript:void(0), it tells the browser to run the JavaScript code 0 (which does nothing) and then discard the result, so the page does not navigate away. This was a common trick to create links that trigger JavaScript actions without leaving the current page.

For example, <a href="javascript:void(0)" onclick="myFunction()">Click me</a> runs myFunction() when clicked, but the browser stays on the same page because the void(0) prevents the default link behavior.

Why Do You See “javascript:void(0)” in the Browser?

You might see javascript:void(0) in the status bar, address bar, or as a page title when:

  • A link with href="javascript:void(0)" is clicked and the JavaScript function it calls fails (e.g., due to an error in the script).
  • A webpage uses javascript:void(0) as a placeholder for an action that requires JavaScript, but JavaScript is disabled in your browser.
  • A browser extension or malicious script injects javascript:void(0) into a page to hijack clicks.
  • The page itself is poorly coded and uses javascript:void(0) instead of proper event handling, causing unexpected behavior.

In most cases, seeing javascript:void(0) is a symptom, not the root cause. The actual problem is that the JavaScript on the page is not executing correctly.

How to Fix the “javascript:void(0)” Error in Your Browser

If you are a user encountering this issue on a website, try these steps in order:

  1. Reload the page – Sometimes a temporary script error causes the link to fail. Press F5 or click the refresh button.
  2. Clear your browser cache and cookies – Corrupted cached files can break scripts. Go to your browser settings, find privacy/clear browsing data, and clear cached images and files.
  3. Disable browser extensions – Extensions like ad-blockers or script-blockers (e.g., NoScript) can interfere with JavaScript. Try disabling them temporarily or using incognito/private mode.
  4. Enable JavaScript – Check that JavaScript is not disabled in your browser settings. In Chrome: Settings → Privacy and Security → Site Settings → JavaScript → Allowed. In Firefox: about:config → javascript.enabled → true.
  5. Update your browser – Older browser versions may have bugs that break modern JavaScript. Install the latest update.
  6. Try a different browser – If the issue persists, the problem might be browser-specific. Test the page in another browser.
  7. Scan for malware – If the issue appears on many sites, your system may be infected. Run a security scan with a reputable antivirus tool.

How to Fix It in Your Own Code (Developers)

If you are a developer and your links use javascript:void(0), consider these improvements:

  • Avoid javascript: URLs altogether – Use href="#" with event.preventDefault() in the click handler, or better, use a <button> element for actions.
  • Use proper event listeners – Instead of inline onclick, attach event listeners in your JavaScript file: document.getElementById('myLink').addEventListener('click', function(e) { e.preventDefault(); myFunction(); });
  • Ensure your functions exist – If the function called by the link is not defined or throws an error, the link will fail. Use browser developer tools (F12) to check the console for errors.
  • Provide a fallback – If JavaScript is disabled, the link should still do something sensible, like navigate to a real page. Use progressive enhancement.

Common Misconceptions About void(0)

Many people think void(0) is a security risk or a virus. It is not. It is a standard JavaScript operator. However, attackers can use javascript: URLs in phishing emails or malicious ads to run scripts, which is why some email clients and security software block them. Seeing javascript:void(0) in your browser does not mean you are hacked—it usually just means a script failed.

Another misconception is that void(0) is the same as undefined. It returns undefined, but it is a separate operator. Using void 0 is a common way to get undefined safely, since undefined can be overwritten in older JavaScript versions.

Alternatives to javascript:void(0)

Modern web development discourages javascript: URLs. Better alternatives include:

  • href="#" with a click handler that calls preventDefault() – Simple and works with JavaScript enabled.
  • <button> elements – Semantically correct for actions, no navigation needed.
  • Data attributes with event delegation – For example, data-action="doSomething" and a global listener.

These approaches keep your code cleaner and more maintainable, and they avoid the confusing javascript: protocol entirely.

Frequently Asked Questions

Is javascript:void(0) a virus?

No, it is not a virus. It is a JavaScript operator that returns undefined. However, malicious actors can use javascript: URLs to execute harmful scripts, so you should be cautious if you see it in unexpected places like email links.

Why does the page show “javascript:void(0)” in the title bar?

This happens when a link with href="javascript:void(0)" is clicked and the browser tries to execute it, but the script fails or is blocked. The title bar may display the URL of the current page, which is the javascript: URL. It is not a separate page—just the browser showing the pseudo-URL.

How do I enable JavaScript in my browser?

In Chrome, go to Settings → Privacy and Security → Site Settings → JavaScript and ensure it is set to “Allowed”. In Firefox, type about:config in the address bar, search for javascript.enabled, and set it to true. In Safari, go to Preferences → Security and check “Enable JavaScript”.

Can I block javascript:void(0) links with an extension?

Yes, script-blocking extensions like NoScript (Firefox) or ScriptSafe (Chrome) can block JavaScript from running, which prevents javascript: URLs from executing. However, this may break many websites that rely on JavaScript, so use it selectively.

Why does my website’s button do nothing when clicked?

If the button uses onclick="myFunction()" and myFunction is not defined or throws an error, the click will do nothing. Open the browser’s developer console (F12) and look for red error messages. Also check that the script that defines the function is loaded before the button is clicked.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →