0

I am using a jquery lightbox plugin on a Wordpress site that opens videos fetched from rss in lighbox and I want to be able to construct a URL like which will send the user to my website and open the video on pageload. This with several videos on the same page.

Then display a button with each videos unique url as a sharebutton.

From googling around something like this could be a way?

  1. jquery get
  2. pass query param with unique url
  3. jquery to open lightbox
  4. jquery to load video plugin (youtube etc.)

Im not good at either jquery or vanilla js, but trying to grasp the concept. Any help appreciated.

Lumi Lu
  • 3,289
  • 1
  • 11
  • 21
Infotheek SE
  • 123
  • 1
  • 1
  • 10

1 Answers1

0

Using a URL Query param is a good option to accomplish this. What we'll do is have a script that checks whether or not the Param exists. I've included code on how to do this. It's all done in javascript.

//This function will check if the current page has the query param of 'video' (or whatever you set it to) & then call your lightbox function.
//Put this in the footer of that page
function checkParam() {
    var isVideo = getParameterByName('video');
    if(isVideo == 'true') {
        //call lightbox open function
    }
}
checkParam();


//I'll use this function to get URL query params: http://stackoverflow.com/a/901144/2106563
//This should also go in the footer of the page
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

As for adding a youtube video within your lightbox, it can be done pretty easily with a link similar to this:

href="//www.youtube.com/embed/dQw4w9WgXcQ?feature=player_detailpage&rel=0&autoplay=1

The only part that you need to change between videos is: dQw4w9WgXcQ. That can be seen in the URL in the browser.

You'll notice that there are Query Params in the URL. One of them is autoplay. There are a bunch of others too if you wish to customize the link a bit more.

EnigmaRM
  • 7,523
  • 11
  • 46
  • 72