Last active
December 23, 2015 23:59
-
-
Save cowboy/6713986 to your computer and use it in GitHub Desktop.
javascript: get last script by src filename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For Remy | |
function getLastScriptBySrc(filename) { | |
var scripts = document.scripts; | |
var i = scripts.length - 1; | |
while (i--) { | |
if (scripts[i].src.slice(-filename.length) === filename) { | |
return scripts[i]; | |
} | |
} | |
return null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var script = getLastScriptBySrc("/1.js"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note: untested in anything but Chrome latest