Javascript: void (0) in hyperlink

Source: Internet
Author: User
When you browse a webpage, you will often find javascript: void (0) in the lower left corner of the browser ). I didn't understand what it meant at the beginning, and I learned the reasons as I learned more deeply. The students joked that this was a major. Some information is missing, and the results are sorted out and used later .... SyntaxHighlighter. all (); when you browse a webpage, you will often find javascript: void (0) in the lower left corner of the browser ). I didn't understand what it meant at the beginning, and I learned the reasons as I learned more deeply. The students joked that this was a major. Some information is also missing, and the results are sorted out and used later.
If you want to do nothing after clicking a link or respond to the click to complete other tasks, you can set its property href = "#". However, this may cause a problem, when a page has a scroll bar, it will return to the top of the page after clicking it. the user experience is poor. There are currently several solutions:
1) do not do anything after clicking the link
1. test
2. test
3. test // use 2 to 4 #. For details, see "#####" and "# all ".
2) click the link to respond to user-defined click events
1. test
2. All problems have been solved, including browser incompatibility. // or you can directly use href = ""
3. test
Note:
1. javascript: the pseudo-Protocol void (0) is rarely written. If you have read some standard web books, you will know why. (Do not understand, the original words are extracted, and the record is made for now)
2. the direct use of javascript: void (0) by Link (href) in IE may cause some problems, such as: causes the GIF animation to stop playing. Therefore, the safest way is to use "####". To prevent the link from jump to the top, The onclick event return false.
3. You can use
Click Me!
Void is a javascript operator that only executes expressions but does not return values,
The format of the void operator is as follows:
1. javascript: void (expression)
2. javascript: void expression
We recommend that you use the second type with parentheses for a good program style.
We can use the void operator to specify the hyperlink, such as javascript: void (document. form. submit ()). The expression is calculated, but no content is loaded in the current document. void (0) is calculated as 0, but it has no effect on JavaScript, that is, the same effect.
The effect is the same.
The key is as long as you know that void is the operator of javascipt itself, it indicates that only expressions are executed, but no return value is returned! In addition, the page is automatically adjusted back to the top because "#" is the top position by default, so this situation occurs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.