如何在视频停止后重定向到主页

时间:2015-08-13 20:50:42

标签: javascript html css redirect cincopa

我正在使用Cincopa将我的视频嵌入到我的网站中。嵌入的页面将被隐藏,导航将被删除。所以我想在视频播放完毕后将所有人重定向到主页。

这是我的代码:

<div id="cp_widget_55a42f1b-6e51-4738-87f9-eaf52dc6a826">...</div>
<script type="text/javascript">
    var cpo = [];
    cpo["_object"] = "cp_widget_55a42f1b-6e51-4738-87f9-eaf52dc6a826";
    cpo["_fid"] = "AsBAj2M3MQOr";
    var _cpmp = _cpmp || [];
    _cpmp.push(cpo);
    (function() {
        var cp = document.createElement("script");
        cp.type = "text/javascript";
        cp.async = true;
        cp.src = "//www.cincopa.com/media-platform/runtime/libasync.js";
        var c = document.getElementsByTagName("script")[0];
        c.parentNode.insertBefore(cp, c);
    })();
</script>
<noscript>Powered by Cincopa <a href='http://www.cincopa.com/video-hosting'>Video Hosting for Business</a> solution.<span>Test</span><span>bitrate</span><span> 39961 kb/s</span><span>height</span><span> 1080</span><span>duration</span><span> 00:02:35.31</span><span>lat</span>:<span> +33.2269</span><span>long</span>:<span> 21-96.93</span><span>fps</span><span> 59.94</span><span>width</span><span> 1920</span><span>originaldate</span><span> 2015-06-06 19:08:58</span>
</noscript>

2 个答案:

答案 0 :(得分:8)

Cincopa嵌入视频HTML标记,您必须按照here

的说明添加事件

嗯,现在我不太愿意做一个完整的测试,所以我只是建议你需要适应的解决方法。

为了给你准确的代码,我需要知道:

  1. 您使用的是什么CMS?
  2. 您可以使用cincopa在视频代码中添加ID或类吗?
  3. 你是否包括jQuery?
  4. 然后你必须在脚本的底部添加这些行:

    //Wait until the page is entirely loaded, and so you can access the rendered video tag (you'll need jQuery)
    $( document ).ready(function() {
    
        function goHomeYouAreDrunk(e) {
            window.location.href = "http://url.to.your.home.page";
        }
        //I'm supposing that your video is the sole video tag in your page, if it's not, you'll have to get it by it's id or class
        document.find('video').addEventListener('ended',goHomeYouArDrunk,false);
    });
    

答案 1 :(得分:1)

通常,这将通过TT元素上的事件监听器。

如何添加事件监听器| W3Schools: https://www.w3schools.com/Jsref/met_element_addeventlistener.asp

但我用Javascript做的一种方法是确定:

<audio>

虽然如果您对性能保持警惕并且不想使用<video>函数,那么请坚持向元素添加事件。

顺便说一下,要重新定向到另一个页面,请使用Javascript函数// The interval clocks every .1 second(s). setInterval(function() { // If the element's current playback time is the playback duration (has reached the end). if (audioElement.currentTime == audioElement.duration) doSomething() }, 100)