How to Avoid Javascript Void

Save

The "javascript:void(0);" statement is often when a link has no URL attached to it but is used to reference a JavaScript function. If there is no URL attached to the link, the browser does not know what to do and returns you to the top of the page. Using "javascript:void(0)" in this instance can cause certain browsers to present your web page in unusual ways. Instead, you should use the "return false;" statement to tell the browser not to look for the URL.

Things You'll Need

  • Text editor
  • Open the document in any text editor.

  • Locate the "javascript:void(0)" references within the document.

  • Replace the links with the pound symbol (#) with the syntax "<a href="#"'>."

  • Add the "return false" declaration to the statement. The entire link reference would look like:

    <a href="a" onClick="callFunction();return false;">Link</a>

    Replace "callFunction()" with the name of your function.

  • Save and close the file.

References

Promoted By Zergnet

Comments

You May Also Like

  • What is JavaScript Void?

    Tizag: JavaScript Void 0 Tutorial; Cubiczone: The Infamous JavaScript Void() Function; Resources. TopBits: JavaScript Void(0) Errors; D'bug: Avoid the Void;

  • How to Fix Javascript Void

    Javascript void errors occur when the user blocks Javascript coding on the web browser. Javascript is a small language used to dynamically...

  • How to Remove a Javascript Void

    Javascript is a client-side language used for website programming. A Javascript void(0) error occurs for several reasons, but it is an easily...

  • How to Use the Void Function

    Tizag; Javascript Tutorial - Void 0; Quackit; JavaScript Void(0) University of Virginia; Computer Science Department; Valued Functions and Void Functions;

  • How to Use OnClick in JavaScript

    Note the use of single quotes for strings within the JavaScript code to avoid conflicting with the double quotes used for the...

  • How to Fix a JavaScript Error

    JavaScript errors are denoted by a small yellow icon in your Internet Explorer browser. ... How to Fix Javascript Void. Help With...

  • How to Enable JavaScript in Windows 7

    JavaScript is a browser-based scripting language used by millions of websites. It allows programmers to create Web pages capable of delivering dynamic...

Related Searches

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!