我正在将静态HTML + JS站点加载到WKWebView中,并且希望向窗口对象上的值分配一些JS函数。
我正确地将脚本添加到html中。我已经使用ES6导入/导出尝试了常规脚本标签和模块:
<script>
window.test = () => {
console.log("I am a normal JS script!");
};
</script>
<script type="module" src="test.js"></script>
// test.js的内容
// This is where I would normally import a function from another module
window.test = () => {
console.log("I am a JS module script!");
};
从WKWebView中检查窗口对象时,在窗口对象上看不到分配的功能(通过我的JS脚本分配)。