从页面中删除所有内容,并用团结游戏onclick替换



标题不言自明。我试图隐藏一个隐藏的href,当点击它时,它会删除页面上的所有内容,在将团结游戏作为整个页面插入之前,让它保持一秒钟的空白。

以下是我迄今为止的收获。

<!DOCTYPE html>
<html>
<script>
function wipeHTML() {
document.documentElement.innerHTML = nothing; //NEED HELP HERE
then wait 1 second
document.documentElement.innerHTML = unity game loads; //NEED HELP HERE
}
</script>
<!-- UNITY STUFF -->
<head>
<link rel="stylesheet" href="TemplateData/style.css">
<script src="TemplateData/UnityProgress.js"></script>
<script src="TemplateData/unityloader41.js"></script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/slope.json", {
onProgress: UnityProgress,
Module: {
onRuntimeInitialized: function() {
UnityProgress(gameInstance, "complete")
}
}
});
</script>
</head>
<body style="margin: 0; overflow: hidden;">
<div class="webgl-content">
<div id="gameContainer" style="width: 100%; height: 100%; margin: 0;"></div>
</div>
</body>
<!-- UNITY STUFF END -->
<h1>
<a href="javascript:wipeHTML">wipe everything</a>
</h1>
<div>
<h1>
hello
</h1>
<h3>
erase me
</h3>
</div>

告诉我我做错了什么!🤷‍♂️

清除页面正文:

document.body = document.createElement("body");

要显示游戏,请添加一个超时,用显示游戏的代码替换console.log。

setTimeout(() => console.log("load unity here"), 5e3)

最新更新