从今天早上开始,我就遇到了一个问题,使用 Apps 脚本部署的 web 应用程序以前运行良好。当然,没有做出任何改变来证明这个问题的合理性。
外部脚本不会从 HTML 端加载,并且控制台中会出现新错误。
为了有一个可重现的例子:
代码.gs
function doGet() {
var template = HtmlService.createTemplateFromFile('index');
return template.evaluate()
.setTitle('TEST')
.addMetaTag('viewport', 'width=device-width, initial-scale=1')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
}
Run Code Online (Sandbox Code Playgroud)
索引.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div id="title">Hello</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
window.onload = function() {
console.log('loaded');
console.log($('#title').html());
}
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
控制台中的结果:
[ERROR] This document requires 'TrustedHTML' assignment. (jquery.min.js:2)
[ERROR] Uncaught TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment. (jquery.min.js:2)
[LOG] loaded …
Run Code Online (Sandbox Code Playgroud)