Get filename from URL using Javascript
http://befused.com/javascript/get-filename-url
Get filename from URL using Javascript
This snippet will get the filename from the url. The filename is the last part of the URL from the last trailing slash. For example, if the URL is http://www.example.com/dir/file.html then
file.html is the file name.
Explanation
- var url = window.location.pathname;
This declares the url variable and adds the current pathname as its value.
- var filename = url.substring(url.lastIndexOf('/')+1);
- alert(filename);
substring (method) - extract characters from start (parameter).
url is the stringObject url.substring(start)
lastIndexOf (method) - position of last occurrence of specified string value, in this case the '/'
Add one to lastIndexOf because we do not want to return the '/'
Full snippet
- var url = window.location.pathname;
- var filename = url.substring(url.lastIndexOf('/')+1);
- alert(filename);
Other question:
https://stackoverflow.com/questions/423376/how-to-get-the-file-name-from-a-full-path-using-javascript
https://stackoverflow.com/questions/680929/how-to-extract-extension-from-filename-string-in-javascript
Get filename from URL using Javascript的更多相关文章
- 【转】关于URL编码/javascript/js url 编码/url的三个js编码函数
来源:http://www.cnblogs.com/huzi007/p/4174519.html 关于URL编码/javascript/js url 编码/url的三个js编码函数escape(),e ...
- 关于URL编码/javascript/js url 编码/url的三个js编码函数
关于URL编码/javascript/js url 编码/url的三个js编码函数escape(),encodeURI(),encodeURIComponent() 本文为您讲述关于js(javasc ...
- 关于URL编码/javascript/js url 编码
一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符号.比如,世界上有英文字母的网址 “http://www.ab ...
- javascript获取当前url
在WEB开发中,许多开发者都比较喜欢使用javascript来获取当前url网址,本文就此为大家总结一下比较常用获取URL的javascript实现代码,以下示例是前面为相应实现方法,后面是获取URL ...
- JavaScript URL传值过程中遇到的问题及知识点总结
JavaScript URL传值过程中遇到的问题及知识点总结 Web系统开发过程中经常用到URL进行传值,刚刚接触时不太会解析,会出现中文乱码问题等. 1.父子页面之间的传值(在一个页面中以加载ifr ...
- 超实用的 JavaScript 代码片段( ES6+ 编写)
Array 数组 Array concatenation (数组拼接) 使用 Array.concat() ,通过在 args 中附加任何数组 和/或 值来拼接一个数组. const ArrayCon ...
- 关于在SharePoint 2013(2010)中Javascript如何实现批量批准的自定义操作功能?
1.概述: SharePoint 2013(包括SharePoint 2010)提供了很方便的,多选的界面,但是很多操作还是不能批量进行,比如:批准的功能.如果您要解决方案不关心代码,那么请直接联系作 ...
- 通过url 下载文件
1.问题简介 通过文件的url,将文件下载到本地.文件存储的位置为:tomcat服务器的文件夹(通过读取properties文件:可看:http://www.cnblogs.com/0201zcr/p ...
- 8年javascript知识点积累
08年毕业就开始接触javascript,当时是做asp.net发现很多功能用asp.net控件解决不了,比如checkbox单选,全选问题,自动计算总价问题,刷新问题,等等.那时感觉javascri ...
随机推荐
- Spark算子讲解(二)
1:glom def glom(): RDD[Array[T]] 将原RDD的元素收集到一个数组,创建一个数组类型的RDD 2:getNumPartitions final def getNumPar ...
- ethereum/EIPs-155 Simple replay attack protection 35,36
EIP 155:重放攻击保护——防止了在一个以太坊链上的交易被重复广播到另外一条链. 在看椭圆曲线时有提到,与r.s.v中的v相关 不同的共有链定义不同的chainId, 防止同一笔交易在不同的共有链 ...
- day06数据类型----元组、字典、集合
一.元组(tuple): python中将一些不能修改的值称为不可变的,而不可变的列表则被称之为元组. 注意元组一旦被定义则不可修改,因此一般我们不定义空元组. 元组是有序的,可存放多个数据| ...
- 使用zip.js压缩文件和解压文件
zip.js官方网站为:https://stuk.github.io/jszip/ 在此说明,下面的例子基本上来自官方示例,大家可以做参考,官方示例地址为:https://stuk.github.io ...
- MariaDB CEO 痛斥云厂商从不回馈社区
导读 MariaDB 首席执行官 Michael Howard 表示,亚马逊和 Oracle 将客户牢牢锁定.他还想知道 AWS 是否可能对 AWS MariaDB 实例动手脚,好让 AWS 自己的数 ...
- 使用 Apache Web 配置多个站点
导读 如何在流行而强大的 Apache Web 服务器上托管两个或多个站点.这篇文章的环境是 Fedora 27 虚拟机,配置了 Apache 2.4.29.如果你用另一个发行版或不同的 Fedora ...
- undefined == false 么
今天碰到个问题,我需要去判断 undefined == false 会返回什么,想当然的以为会返回true,但是结果却返回的是false,这我就有点晕了,不是说undefined.null.0.NaN ...
- ESP32 电容式触摸按键设计
手指和电容器接触时,相当于增加了电容,电容增加量与总电容的商就是电容的变化幅值,如果这个幅值超过门限,就认为触摸按键被激发了:
- python常用工具组件
1.JS 正则 test - 判断字符串是否符合规定的正则 rep = /\d+/; rep.test("asdfoiklfasdf89asdfasdf ...
- Intel Artificial Intelligence Conference(2018.11.14)
时间:2018.11.14地点:北京国贸大酒店