Search code examples
javascriptjquerytwitter-bootstrapurlurl-routing

Is it possible to automatically open a video modal and begin playing only when the user accesses the page from a link in an email.?


I know that we can open Bootstrap modal on page load very easily. But I have a situation where the modal should open ONLY when the user accesses the page from an email link?

Is there any way to do using JavaScript or JQuery.


Solution

  • Yes, you can.

    The most straightforward way I can think of is to use an extra query parameter in the url used in the email.

    When your page loads, you can test for this query parameter and then decide to open your modal or not.

    Consider this sample URL:

    www.example.com

    In the email version, we can add a query parameter like this :

    www.example.com?email=true

    and then, on your client side (on page load):

     var query = window.location.href.split('?')[1];
     if(query && query.indexOf('email=true') > -1){
         // Url has the parameter run code to open modal
     }