Href=javascript:; Clear the default behavior of the A label

Source: Internet
Author: User

href= "javascript:;" is to get rid of the default behavior of the A tag, which is the same as href= "javascript:void (0)"
"The following content is reproduced in the original link: http://www.cnblogs.com/xd502djj/archive/2010/11/10/1874107.html"

Links in the page in addition to the general way, if you use JavaScript, there are many ways, here are some ways to open the link using javascript:

1. Open the link using the Open method of window, which opens the link in the development page, can also customize the size of the open page, and so on.
<a href= "Javascript:window.open (' http://www.google.com ', ' _self ')" > Open a link 1</a><br/>

2. Use document. URL property to hit a new page. Not enough of this method seems to work in Firefox.
<a href= "Javascript:document. URL = ' http://www.google.com ' > Open a link 2</a><br/>

3. Use the location's attribute href to open the link.
<a href= "javascript:window.location.href= ' http://www.google.com '" > Open a link 3 </a><br/>

4. Use location method assign to open the link, this effect is the same as in the previous way.
<a href= "javascript:window.location.assign (' http://www.google.com ')" > Open a link 4</a><br/>

5. Use the location method replace to open the link, and the previous assign way slightly different, the difference is that the use of replace when the page is replaced by the URL will not enter the history object, This means that you cannot go back to the page you are replacing.
<a href= "Javascript:window.location.replace (' http://www.google.com ')" > Open a link 5</a><br/>

6. Normal links, of course, this is the most friendly way to search engines, you can also do the specified link to open the window. Only in this way can the linked page be crawled by search engine spiders.
<a href= "http://www.google.com" > Open a link 5</a><br/>

Href=javascript:; Clear the default behavior of the A label

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.