再生が終了した後、html5 ビデオで自動的に別のページを開くことは可能ですか?
これはJavaScriptでどのように行うことができますか?
MDN のメディアイベントを見てください。
// 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]'
});
これが実用的なフィドルです。
If you are using jQuery you can do it this way:
$("#myVideoElementID").bind("ended", function() {
// Do stuff here
});