87,910
社区成员
发帖
与我相关
我的任务
分享
function requireOnce(scriptPath) {
var scripts = document.getElementsByTagName("script");
for (var index = 0; index < scripts.length; index++) {
if (scripts[index].src.lastIndexOf(scriptPath) != -1) {
return;
}
}
var scriptTag = document.createElement("script");
scriptTag.type = "text/javascript";
scriptTag.src = scriptPath;
var headTag = document.getElementsByTagName("head")[0];
headTag.appendChild(scriptTag);
}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
<title>Insert title here</title>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
requireOnce("js/glUtils.js");
requireOnce("js/glUtils.js");
requireOnce("js/glUtils.js");
requireOnce("js/glUtils.js");
</script>
</head>
<body>
</body>
</html>