I'm having an issue with the following script. The calling script is: script src="//192.168.6.10/js/cYJIeCa30E.js the resulting script needs to be parsed for cYJIeCa30E.js in this script I have:
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript.src;
var name = scriptName.split('/');
alert(name);
alert(name) gives comma separated values:
http:,,192.168.6.10,js,cYJIeCa30E.js
but
alert(name[4]) gives ':' not the value after the last '/'
any idea what I am missing?
Thanks
The proper way will be like so:
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript.src;
var a = scriptName.split('/');
alert(a[4]); //cYJIeCa30E.js
Note You can change the variable a
to any other variable. Thanks to Mike C
for the MDN link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.