0

I have a page (somepage.aspx) that has a popup video on it. The video opens when a link is clicked using the js $('.showVideo').live('click', function() {

I have another page (otherpage.aspx) and would like to link to /somepage.aspx with some kind of URL parameter that automatically opens the video popup. Something like /somepage.aspx?video=1 ... based on the url parameter the video would open. How would I add this to my existing js?

Thanks

AaronSantos
  • 159
  • 1
  • 7
DevKev
  • 5,714
  • 6
  • 24
  • 29

1 Answers1

1

Using this function you are able to detect the presence of ?video=1 in the url:

function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

Source: Get escaped URL parameter Credit to https://stackoverflow.com/users/726427/pauloppenheim

Then you could do something like:

if(getURLParameter('video')==1){
  $(".showVideo").trigger('click');
}

edit:

$(document).ready(function(){               


    function getURLParameter(name) {
        return decodeURI(
            (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
        );
    }
    if(getURLParameter('video')==1){
      $(".showVideo").trigger('click');
    }
});

Wrap the parameter name(video) in quotes getURLParameter('video').

Another Edit

Wrap your click event handler in a function, basically remove everything form:

$('.showVideo').live('click', function() {
    //build overlay
    (...)
    return false;
});

Cut&paste it inside a function. Then just call the function from inside:

$('.showVideo').live('click', function() {
    my_function();
});

Then change the previous code to:

if(getURLParameter('video')==1){
     my_function()
}
Community
  • 1
  • 1
AaronSantos
  • 159
  • 1
  • 7
  • Page from: http://bit.ly/RElMs2 (the link under 2008). I added the script to the head of http://bit.ly/RElNMt No luck, did I add that correctly? – DevKev Dec 06 '12 at 15:21
  • @KevinW.me Your jQuery needs to be inside the $(document).ready function. I just looked at your source code at http://lg.priworks.com/overview.aspx?video=1. I'll edit my answer. – AaronSantos Dec 06 '12 at 15:25
  • Tried it their before too. I added to the video js in $(document).ready function. and still nothing. – DevKev Dec 06 '12 at 15:28
  • Thanks "js/jquery/jquery.videobox.js" by the way – DevKev Dec 06 '12 at 15:29
  • Clicking the video popup links on the page also no longer works – DevKev Dec 06 '12 at 15:31
  • @KevinW.me that's because video was being treated as a variable and it was not assigned(if you are using chrome check your console). Don't forget to wrap it in quotes. – AaronSantos Dec 06 '12 at 15:33
  • Any idea why after closing the video popup it would show CLOSE CLOSE text on the right of the sreen? http://bit.ly/REsb6y – DevKev Dec 06 '12 at 16:00