Skip to content

Instantly share code, notes, and snippets.

@geckotang
Created June 6, 2013 08:11
Show Gist options
  • Save geckotang/5720052 to your computer and use it in GitHub Desktop.
Save geckotang/5720052 to your computer and use it in GitHub Desktop.
読み込まれたscript要素の位置を取得する
<script id="testscript" src="test.js">
<script id="testscript2" src="test2.js">
// http://d.hatena.ne.jp/amachang/20061201/1164986067
(function(){
var currentScript = (function ( e ) { if(e.nodeName.toLowerCase() == 'script') return e; return arguments.callee(e.lastChild) })(document);
alert(currentScript.id); // testscript
}());
// https://twitter.com/uupaa/status/342558346794110976
(function(){
var currentScript = document.scripts[document.scripts.length-1];
alert(currentScript.id); // testscript2
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment