2

再生が終了した後、html5 ビデオで自動的に別のページを開くことは可能ですか?

これはJavaScriptでどのように行うことができますか?

4

2 に答える 2

1

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]'
});​

これが実用的なフィドルです。

于 2012-06-01T11:38:46.967 に答える
0

If you are using jQuery you can do it this way:

$("#myVideoElementID").bind("ended", function() {
  // Do stuff here
});
于 2012-06-01T11:42:08.167 に答える