Last active
March 7, 2025 23:48
-
-
Save tyfkda/b027ed4b79d5aa22408d to your computer and use it in GitHub Desktop.
自分自身のscriptタグを取得する ref: https://tyfkda.github.io/blog/2014/11/07/self-script-tag.html
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 currentScript = document.currentScript || (function() { | |
| var nodeList = document.getElementsByTagName('script') | |
| return nodeList.item(nodeList.length - 1) | |
| }()) | |
| var text = currentScript.text // text で内部テキストが取得できる。 | |
| //=> "\n ここのテキストを取得したい\n " |
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
| <script src="get_current_script.js"> | |
| ここのテキストを取得したい | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment