【问题标题】:deep link video url on a webpage网页上的深层链接视频网址
【发布时间】:2013-05-12 19:11:03
【问题描述】:

我有一个视频页面,上面有本地托管的视频和 3 个缩略图,当点击它们时,它们会加载到一个主视频 div 中 - 这很有效并且很棒。我唯一的问题是当您加载视频 1、2 或 3 时,它们顶部的 url 保持不变。有没有一种深度链接的方法,所以 url 更改为网站 url/#video-1 等等?进行了一项研究,并且从我目前构建的内容中不确定如何将其集成到其中。任何链接/教程都会很棒

这是我目前所拥有的:

JS:

    //video gallery
     $(".thumbnail-1,.thumbnail-2,.thumbnail-3").on("click", function(event) {
      event.preventDefault();
      $(".main_stage iframe").prop("src", $(event.currentTarget).attr("href"));
      loadURL($(this).attr('href'));
    });
});

【问题讨论】:

    标签: jquery url deep-linking


    【解决方案1】:

    可能是这样的:

    $(window).load(function() {
        // get hash string eg. #video1
        var hash = window.location.hash;
    
        if (hash == '#video-1') { // do some checks, you can apply regex or switch
            // I'm not sure what your html looks like
            $(".main_stage iframe").prop("src", $('selector').attr("href"));
            loadURL($(this).attr('href'));
        }
    });
    
    $(".thumbnail-1,.thumbnail-2,.thumbnail-3").on("click", function(event) {
        var className = $(this).attr("class"); // get class name of clicked element
        var videoId = className.split("-").pop(); // split string to get video id => "1, 2, 3 etc."
    
        window.location.hash = '#video' + videoId; // change url to eg. #video1
        event.preventDefault();
        $(".main_stage iframe").prop("src", $(event.currentTarget).attr("href"));
        loadURL($(this).attr('href'));
    });
    

    如果您要基于正则表达式 (fiddle here) 进行验证,您可以使用以下代码:

    var hash = window.location.hash;
    var regex = new RegExp('^#video-[0-9]{1,10}$');
    
    if (regex.test(hash)) {
       // if hash is something like "#video-[NUMBERS]" then do something
    }
    

    【讨论】:

    • 这正是我想要的,谢谢!你能解释一下缩略图部分的第二个功能,这样我就知道自己是如何工作的,而不是拿你的 sn-p 吗?谢谢:)
    • 我会尝试添加一些 cmets。
    • 谢谢你,我会看看这个,就像我边走边学:)
    猜你喜欢
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多