我试图找出当前JavaScript在运行脚本标签的位置.什么是怎么回事的是,我需要确定里面一个src'd,动态插入的JavaScript文件所在的DOM.这些是动态生成的标签; 代码段:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>where am i?</title>
<script type="text/javascript" charset="utf-8">
function byId(id) {
return document.getElementById(id);
}
function create_script(el, code) {
var script = document.createElement("script");
script.type = "text/javascript";
script.text = code;
el.appendChild(script);
}
</script>
</head>
<body>
<div id="find_me_please"></div>
<script>
create_script(byId("find_me_please"), "alert('where is this code located?');");
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)