Dynamically change video URL inside Lightbox window

Asked

Viewed 132 times

2

Hello, my question is about dynamic video url change. When clicking on a function (open lightbox) opens a lightbox window, and inside this janaela I need to open video dynamically, today opens a static.

I have two segments (car and bike), within each segment I have two box that when clicked appears a Thumb/image where when being clicked loads the corresponding video.

When I click on a box it opens at the bottom of the box and when I click on the other box it opens the same box. Clicking on this button triggers the function that mounts the lightbox with the video. The goal is to open these videos dynamically.

'data-vehicle is an attr that identifies the selected box.

function selecionaUrl(veiculos) {
    var boxA = $(".box-veiculo[data-veiculo=A]");
    var boxB = $(".box-veiculo[data-veiculo=B]");
    if (veiculoSegmento == 'carros'){
        if (boxA == $(".box-veiculo-selected")){
            $('#video').attr("href", "https://www.youtube.com/embed/xxxxx");
            return true;    
        }
        else if (boxB == $(".box-veiculo-selected")){
            $('#video').attr("href", "https://www.youtube.com/embed/yyyyy");
            return true;    
        }

    }else if (veiculoSegmento == 'motos'){
        if (boxA == $(".box-veiculo-selected")){
            $('#video').attr("href", "https://www.youtube.com/embed/wwwww");
            return true;    
        }
        else if (boxB == $(".box-veiculo-selected")){
            $('#video').attr("href", "https://www.youtube.com/embed/zzzzz");
            return true;    
        }
    }
}

Inside the archive js, the variable mounting the lightbox and being concatenated by (vehicles):

var htmllgtbox = '<div id="" </div> ' + '<iframe ' + veiculos + '</iframe>'
  • You want those Urls, for example, https://www.youtube.com/embed/xxxxxare dynamic in this function above, according to the clicked Thumb?

  • DVD, yes, when clicking on Thumb call the function via href="javascript:openlightbox();" this function calls another function with a variable that mounts the lightbox, in this var concateno the video

  • There are some problems with your code, and one I’ve already fixed: there was a } remaining at the end. And in some if you put only one =, when the correct would be two ==.

  • For starters, you can already think about sending to the function that opens the videos the YT code of the video, something like: javascript:abrirlightbox('codigo_video')... and send it to the function selecionaUrlVeiculo()

  • yes, I had to do the code again, because in the environment I’m not able to copy the code, I had to redo outside

  • DVD, I have 4 different videos, need to call them dynamically, not calling along with the function to open lightbox.

  • I only have a Thumb that calls the function open lightbox when I click on a box open the bottom of the Thumb when I click on the other box opens the same Thumb

  • It would be interesting to reformulate the question, put the codes involved in all this. For me it was still confused.

  • DVD, the code I made is the same one, but it can be done otherwise to load dynamic, as it can possibly have many more videos to load.

  • It would not send a parameter with the video code to the function selecionaUrlVeiculo()?

  • I didn’t understand the variable selecionaUrlVeiculo if she is a function.

  • no, the variable is htmllgtbox

  • '<iframe ' + selecionaUrlVeiculo + '</iframe>'. The selecionaUrlVeiculo is a variable.

  • By the code in the question, this is being a variable and a function at the same time. Very confusing.

  • has the variable, and how to send a parameter with the video code to the function selectUrlVeiculo()?

Show 10 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.