我试图将webcam.js文件转换为index.html文件,但它需要在页面加载后加载。这是一个网络摄像头文件,所以它只在索引文件加载后才打开。我还必须能够使用该文件中的函数。所以我的外部文件是webcam.js,我在index.html中使用它,我还需要在html文件中使用webcam.js中的showBlue()函数。
(index.html的下半部分)
<script src="C:/Users/Juniper/Documents/Apps/server/webcam.js" defer></script>
<script>
if (window.onload = showBlue) {
window.onload = function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", './screen.html', true);
xhttp.onreadystatechange = function() {
window.location.href = 'screen.html';
};
xhttp.send();
}
}
</script>
</body>
目前,这不会将屏幕更改为screen.html,但如果删除if语句(if (window.onload = showBlue) {),则screen.html将自动加载
发布于 2017-07-14 22:21:48
您可以将其包装在一个间隔计时器中,该计时器会定期检查脚本是否已加载。
var webcamInterval = setInterval( function() {
if ( someWellKnownFunctionNameFromWebcamJs ) {
clearInterval( webcamInterval );
// Your code dependent on webcam.js here ...
}
}, 100 );https://stackoverflow.com/questions/45105027
复制相似问题