根据NaCl progress events 的文档,必须添加事件侦听器,如下所示:
<div id="listener">
<script type="text/javascript">
document.getElementById('listener').addEventListener('load', function() {
// Example
}, true);
</script>
<embed name="nacl_module" ... type="application/x-nacl" />
</div>
如果内容安全策略禁止这样做(另请参阅)。只有一种方法可以解决它:通过将脚本移动到外部文件:
<div id="listener">
<script src="listener-load.js"></script>
<embed name="nacl_module" ... type="application/x-nacl" />
</div>
// listener-load.js:
document.getElementById('listener').addEventListener('load', ..., true);
Because the construction of the DOM blocks until the external file is loaded, the script is loaded before the <embed>
tag is inserted. Since the external files are packaged with the extension, the impact on performance can be neglected.