# Symbol instructions in the URL address _ javascript skills

Source: Internet
Author: User
The following describes the use of #, because multiple # numbers in the url indicate different meanings and differences. Generally, we want a tag a to click and execute javascript code, which can be written in the following ways:
Method 1: Click 1
The disadvantage of this method is that after clicking it, # is added to the URL of the address bar and the page is moved to the top. It is generally not recommended.
Method 2: Click 1
This method avoids the disadvantage of method 1. Clicking this method does not affect the page. However, there is a fatal drawback: in IE6, the submit () method of the form object cannot be executed, nor jump statements can be executed, such
Click 1
Click 1
In IE6, it will be invalid. If it is changed to href = "#", it can be executed normally in IE6.

Method 3: Click 1
After clicking the button, three # numbers are added to the URL in the address bar, but the scroll bar is not affected. In IE6, the submit () method and jump statement of the form object can also be executed, is a relatively discounted method.

Conclusion: I personally think that if the javascript method to be executed needs to submit a form, jump to the page, use method 3, and use method 2 in other cases.

In addition, this introduces another problem. Generally, the following javascript code is used to reload the current page:
Window. location. href = window. location. href;
But when the URL address contains #, the above Code is invalid, so you need to use the following code:
Window. location. href = window. location. href. split ('#') [0];
Split the URL address with the # symbol and take the first part.

In many cases/index.htm # desc, the following desc may be a parameter. It is not easy for parameters to display different content. Instead, it is not a simple anchor, but ajax reads the content.

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.