Use JS code to get the article ID number

Source: Internet
Author: User

Use JS code to get the ID number of the article path

Many CMS are using ID number concatenation article, then how to use JS to get ID number?

After a day of research, finally have the results, the code is as follows:

<script>

var url = location.href;

url = Url.match (/\/(\d*). html/);

document.write (url[1]);

</script>

The code can use a different JS reference.

For example URL: http://www.lc13.cn/yulu/haoju/825.html

Can intercept/start, HTML end of the pure numeric string, so this regular expression can get the ID number is 825.

Of course, your directory path does not use a pure number line.

Get the article ID number can be arbitrarily two times programming, as to what can be done we can www.lc13.cn to free play. (Transferred from: http://www.lc13.cn/jianzhanxinde/853.html)

Use JS code to get the article ID number

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.