0

I have created a plugin to sell videos using woocommerce. The plugin adds license key to view the purchased video. I am facing issue with the youtube video. When i put license key and ajax loads video in a popup. I am getting this error:

Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self' <URL>"

The problem is popup is hidden on page load and the audio of the video starts playing but the video stays on its initial state.

Here is my code:

   function submit_license(control,form_id) {
        //alert(form_id);
        jQuery(control).attr("disabled","disabled");
        jQuery(control).val('Loading..');
        jQuery.post(obj_unvq_custom.ajax_url,jQuery("#"+form_id).serialize()+"&action=license&_wpnonce="+obj_unvq_custom.nounce, function(data){
            jQuery(control).val('Submit');
            jQuery(control).removeAttr("disabled");
            var decoded_data = jQuery.parseJSON(data);
            if(decoded_data.code == "error")
            {
                alert(decoded_data.error);
            }
            else
            {
                close_modal("activation_modal");
                jQuery('#TB_ajaxContent').html('');
                tb_show('', '#TB_inline?height=300&width=400&unvq=true&inlineId=video_popup'+decoded_data.order_id);
                if(video_url != "undefined")
                {
                    jQuery("div.player_responsive").find('iframe').attr('src',video_url);
                }
            }
        });
    }
Developer
  • 43
  • 1
  • 8
  • Maybe [this answer](https://stackoverflow.com/a/35273628/4092887) might help you. if the refusal is from YouTube, I'm affraid you have to find another solution. If you haven't tried yet, search `because it violates the following Content Security Policy directive` on Google. – Mauricio Arias Olave Feb 13 '19 at 15:04
  • Thanks for your reply. I tried the example and it doesn't work for me. `in addition to what you have, you should add http://* to both style-src and script-src as seen above added after 'self'` With this did he mean to add script like `` ? – Developer Feb 14 '19 at 04:14
  • Developer, yes, add http:// as indicated and try. – Mauricio Arias Olave Feb 14 '19 at 13:30
  • Didn't work for me. :( I searched for this and didn't find any solution related to my issue.I think its because i am loading video in a popup. Initially popup is hidden and if i made the popup visible on page load then it works fine. – Developer Feb 15 '19 at 04:39
  • Developer, it is possible that you build a [jsfiddle](https://jsfiddle.net) with the full code? – Mauricio Arias Olave Feb 15 '19 at 14:07

0 Answers0