[英]javascript: get hex from long url
For example i have such urls: 例如我有这样的网址:
https://portalvhdsk7w6i7k9.blob.core.windows.net:443/project/5633cc12da73d9160c4cf146.dat
https://portalvhdsk7w6i7k9.blob.core.windows.com/project/5633cc12da73d9160c4cf146.dat
https://example.com/project/5633cc12da73d9160c4cf146.dat
can i somehow get only 5633cc12da73d9160c4cf146
using only js? 我能以某种方式仅使用js获得5633cc12da73d9160c4cf146
吗? is it possible? 可能吗?
You can split the string by /
and the pop()
the final element. 您可以使用/
分割字符串,然后将pop()
分割为最后一个元素。 Try this: 尝试这个:
var url = 'https://portalvhdsk7w6i7k9.blob.core.windows.net:443/project/5633cc12da73d9160c4cf146.dat'
var hex = url.split('/').pop().replace('.dat', ''); // = '5633cc12da73d9160c4cf146'
If you want to get the location of the current page, use document.location
. 如果要获取当前页面的位置,请使用document.location
。
Check this: 检查一下:
var url = "https://portalvhdsk7w6i7k9.blob.core.windows.net:443/project/5633cc12da73d9160c4cf146.dat" var indexofProd = url.indexOf("project/"); indexofProd = indexofProd + 8; var indexofdotDat = url.indexOf(".dat"); var number = url.substring(indexofProd,indexofdotDat); alert(number);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.