href= "javascript:void (0)"

Source: Internet
Author: User

Personally measured the following:
<a href= "javascript:void (0)" onclick= "on" > Link </a>: Execute on function First, page does not move

<a href= "#" onclick= "on" > Link </a>: Perform the on function first, go back to the top
<a href= "https://www.baidu.com" onclick= "on" > Link </a>: Execute on function First, then skip to Baidu homepage
Supplement <a href= "Javascript:fun ();" : Tune into the fun function



The following is the user summary:
javascript: is a pseudo-protocol that indicates that the contents of a URL are executed through JavaScript.
void (0) means no action is made, which prevents the link from jumping to another page.
This is often done to preserve the style of the link, but does not allow the link to do the actual operation, the specific action to the link onclick event processing


void (0) is a piece of JavaScript code, the return value is undefined,href= ' javascript:undefined ' When you point the link,
But not doing anything. The reason for this is to add the onclick event with JS to this <a>,
To do as a link. The advantage is that the mouse is hand-shaped when linked, and the user does not know what the link is doing.

<a href= "#" onclick= "Window.close ()" > Close </a>
The href= "#" refers to the link to the current page, in fact, is meaningless, the page will not be refreshed, the key is the following onclick, when clicked "Close", will execute the Window.close () code.

You might say why not just write <a onclick= "Window.close ()" > Close </a>
If you write this, closing the two words will not work as a hyperlink, and the effect will look worse. You can try it yourself.

I'll tell you in detail. Javascript:void (0) represents some links with no return value, usually for example:

<a href= "javascript:void (0)" onclick= "on" > Links </a>
There is no return value for the OnClick event, and the page does not change the product. If you don't add this, you'll go back to the top.
Supplement <a href= "Javascript:fun ();"
So click to execute the fun () function

href= "javascript:void (0)"

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.