The first method: regular matching
<script> var strUrl = "///article/"; url = (/\/(\d*)\.(html|htm|shtm|shtml)/); (url[1]); </script>
Replenish
var re = new RegExp(".*/(\\d+)\\.html","ig"); var _aid = "-1"; if(("https:///article/pc/") != null){ _aid = RegExp.$1 }
Practical application code
<script> var strUrl = ; url = (/\/(\d*)\.(html|htm|shtm|shtml)/); (url[1]); </script>
The second method: directly split the page into an array of arrays
<script> var strUrl = ; var arrUrl=("/"); var strPage=arrUrl[-1]; alert((".html","").replace(".htm","")); </script>
The third method: use substring
<script> var strUrl = ; str=(("/") + 1) alert((".html","").replace(".htm","")); </script>
Substring definition and usage
The substring() method is used to extract characters in a string between two specified subscripts.
grammar
(start,stop)
parameter | describe |
---|---|
start | Required. A non-negative integer that specifies the position of the first character of the substring to be extracted in stringObject. |
stop |
Optional. A non-negative integer has 1 more position in stringObject than the last character of the substring to be extracted. If this parameter is omitted, the returned substring will continue to the end of the string. |
Return value
A new string whose value contains a substring of stringObject whose content is all characters from start to stop-1, with a length of stop minus start.
illustrate
The substring() method returns a substring includes the characters at start, but does not include the characters at stop.
If the parameter start is equal to stop, then the method returns an empty string (that is, a string of length 0). If start is larger than stop, the method will swap these two parameters before extracting the substring.
The fourth type: for abnormal parameters on the page
For example ///article/?path=/asdf/ddd
<script> var strUrl = "http:///article/"; //Get the current page name//var strUrl=; var arrUrl=("/"); var strPage=arrUrl[-1]; if(("?")>-1){ var pageName=("?"); strPage=pageName[0]; } alert(("html","").replace(".htm","")); </script>
This article about obtaining the url page id of js, which is the last digital file name, is introduced here. For more related contents of obtaining the url page id of js, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!