如果主视频存储库(smugmug.com)无法访问(公司防火墙),这是我一直在努力更改视频源URL的代码。问题是我必须运行一个循环来等待SMimage.src = "http://smugmug.com/favicon.ico";
加载,并且此代码在smugMugChecked = true
时不会退出循环。 clearInterval()
似乎没有用,即使我将checkInterval
声明为全局变量。
<head>
<script>
var checkInterval = null;
// check if SmugMug is reachable (run once only)
var isSmugMug = "1";
var smugMugChecked = false;
var SMimage = new Image();
SMimage.onload = function () {
window.isSmugMug = "1";
smugMugChecked = true;
// The user can access SmugMug
};
SMimage.onerror = function () {
// The user can't access SmugMug
window.isSmugMug = "0";
smugMugChecked = true;
};
SMimage.src = "http://smugmug.com/favicon.ico";
function changeImage(p1, p2, p3) {
checkInterval = setInterval(function () {
if (smugMugChecked == true) {
clearInterval(checkInterval);
if (window.isSmugMug == 0) {
//Hello();
var player = document.getElementById(p1);
var mp4Vid = document.getElementById(p2);
player.pause();
// Now simply set the 'src' attribute of the mp4Vid variable!!!!
// (...using the jQuery library in this case)
//$(mp4Vid).attr('src', p3);
document.getElementById(p2).src = p3;
player.load();
//player.play();
}
}
}, 500);
}
</script>
</head>
<body>
<video id='video9.1' onloadstart="changeImage('video9.1','source9.1', 'http://videos.ultrasoundoftheweek.com/photos/i-fDJHzts/0/960D/i-fDJHztsD.mp4')" width="792" height="470" controls> <source id='source9.1' src="http://www.ultrasoundoftheweek.com/wp-content/uploads/2014/07/heterotopic.mp4"/>
<source id='else2' src="http://www.ultrasoundoftheweek.com/wp-content/uploads/2014/07/heterotopic.webm"/>
</video>
</body>