是否可以让html5视频在完成播放后自动打开另一个页面?
如何在javascript中完成?
答案 0 :(得分:1)
// Cross-browser attach event logic (might be useful for this one day)
function listen(evnt, elem, func) {
if (elem.addEventListener) { // W3C DOM
elem.addEventListener(evnt, func, false);
}
else if (elem.attachEvent) { // IE DOM
var r = elem.attachEvent("on" + evnt, func);
return r;
}
else alert('I\'m sorry, I\'m afraid I can\'t do that.');
}
// Attach to event
listen("ended", document.getElementById('myVideo'), DoSomething);
// Event handler
function DoSomething() {
// Use window.open (new window), or window.location.href = '[your link]'
}
修改强>
由于您在评论中提到您拥有jQuery,因此也可以使用:
$("#myVideo").on("ended", function() {
// Use window.open (new window), or window.location.href = '[your link]'
});
答案 1 :(得分:0)
如果您使用的是jQuery,可以这样做:
$("#myVideoElementID").bind("ended", function() {
// Do stuff here
});