js兼容性 - 动态删除script标签后 ,定义的函数是否执行

时间:2023-03-09 21:42:23
js兼容性 - 动态删除script标签后 ,定义的函数是否执行
hello.js
function hello(){
alert('hello');
}

hello.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script id="hello" src="hello.js"></script>
</head>
<body>
</body>
<script>
hello();
if (-[1,]) {
document.getElementById('hello').remove();
} else {
document.getElementById('hello').removeNode(true);
}
setTimeout(function(){
hello();
},1000);
</script>
</html>

会执行: Chrome,firefox,IE 11,Opera

不执行: Safari

暂时仅测试这些