Introduction of Javascript:void (0) and its role in website optimization

Source: Internet
Author: User

When doing a page, if you want to do a link click Do not do anything, or respond to click to complete other things, you can set its properties href = "#", however, this will have a problem is that when the page has a scroll bar, click will return to the top of the page, or jump to the set anchor point where the user experience is not good.
The usual usage is:

<a href= "javascript:void (0)" > click here to see the effect </a>

Actually click here and nothing will happen, where the javascript:void (0); The form is a JavaScript pseudo protocol, which means that the link does not jump anywhere.

The use of javascript:void (0) is mainly in the following ways:

Click on the link and don't do anything.
<a href= "javascript:void (0);" >test</a>
<a href= "javascript:;" >test</a>
<a href= "#" >test</a>//Use 2 to 4 #, see mostly "#", also use "#all" and other
Click on the link to respond to user-defined click events
<a href= "javascript:void (0)" onclick= "dosomething ()" >test</a>

void operator usage format is as follows:

#第一种写法:
Javascript:void (expression)
#第二种写法:
Javascript:void expression

Expression is an expression of the JavaScript standard to compute. The parentheses outside the expression are optional, but writing is a good habit. We can use the void operator to specify a hyperlink. The expression is evaluated but does not load any content in the current document. Surface code creates a hyperlink that will not happen when the user clicks on it. When the user clicks on the link, void (0) evaluates to 0, but there is no effect on JavaScript.
That is, you can use void (0) to perform some processing, but not to refresh the page as a whole, but be careful when you need to refresh the page.

When calling from this custom JS function, if we use the

<a href= "#" onclick= "method;" >click</a>

, although the method can be executed, if the page contains scroll bars, it will automatically scroll to the top of the page, if we use

<a href= "javascript:void (0); Onclick= "method;" >click</a>

When executed, the page will not scroll, which should be very useful for picture switching and Ajax invocation.



href= "#" contains a location information. The default anchor is the #top, which is the top of the page, which can cause the browser to collapse or even crash when you click the link continuously.

Of course we usually use three href= "###", but after reading this article we can use JavaScript later.:;(a colon a semicolon)

In JavaScript, Void is an operator that specifies that you want to evaluate an expression but not return a value.

JavaScript.:; better, javascript.:void (0); it is said that in some cases there are browser-compatible bugs. (this point of the bug I do not know when to appear, know the children's shoes please advise).

Can be written as javascript.:;,qq space many are written in JavaScript.:;

I feel that there is no difference between the two, is to execute an empty event.

JavaScript.:; even less than 7 characters, hehe.

Sina Weibo is written by javascript.:void (0);

I used to write Javascript.:void (0), but now it's all JavaScript.:;



the role of javascript:void (0) in website optimization

In our website to promote the optimization process, often need to do a lot of outside the chain on the platform, but to deal with this outside the chain, each platform has its own strategy, such as prohibit you to send a link, after the audit does not pass;
After the link is automatically sent to you to pull hair, even if there is a link, but often is also can not jump, do not have to paste the user to go to your link to the site, so do nothing but want to leave the customer on their own platform.
Finally encountered a few post information, you can jump directly in the information page, in the release of the site also prompted the need to add HTTP. But after the release of the discovery: for example, to do a link:
http://www.yourdomain.org
As a result, this link will be more than this code:
<a href= "javascript:void (0)" onclick= "window.open (http://www.yourdomain.org)" >

What does this code mean? is a link to a Web site entitled to be delivered again?
All know the weight of classification information station is high, although can only leave the chain, but the weight is high and can stay linked to the station is not much, not to mention the classification information station outside the chain can also improve the universality.
Fixed every day will send 3 classified information site outside the chain, hair posts can be instantaneous collection. At that time in the search for the chain of resources, to instantaneous as the primary inspection criteria, but the link itself was ignored.
Today, the time to check the link, found that there is an information site code added to the javascript:void (0), although it is clickable link, but set the JS code search engine will not crawl.
In JavaScript, Void is an operator that specifies that you want to evaluate an expression but not return a value. A search on the internet, found that a lot of responsible for site optimization in question, because someone in the chain of friends to add this,
Too pit Dad, such a station does not co-operate. When you do outside the chain to pay attention to, if the other party to get you the link brought this code, that link is invalid.
Although you can see the other side of the eye to help you make a link, but there is no meaning.


Extended:

Do not track (ie crawl) Any outbound links on a Web page:
<meta name= "Robots" content= "nofollow"/>

Stop spiders from tracking individual links on a Web page:
<a href= "signin.php" rel= "nofollow" >signin</a>

Related Article

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.