Created
June 6, 2013 08:11
-
-
Save geckotang/5720052 to your computer and use it in GitHub Desktop.
読み込まれたscript要素の位置を取得する
This file contains 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
<script id="testscript" src="test.js"> | |
<script id="testscript2" src="test2.js"> |
This file contains 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
// 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 | |
}()); |
This file contains 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
// 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