0

I restate my question here: When I work on a test page of my site (https://www.jobcool.fr/single.html), the youtube videos appear but when I put this page on the internet with filezilla, the videos no longer work. I used a code that can lighten the weight of youtube videos

<script>
  ( function() {

    var youtube = document.querySelectorAll( ".youtube" );

    for (var i = 0; i < youtube.length; i++) {
      
      var source = "https://img.youtube.com/vi/"+ youtube[i].dataset.embed +"/sddefault.jpg";
      
      var image = new Image();
          image.src = source;
          image.addEventListener( "load", function() {
            youtube[ i ].appendChild( image );
          }( i ) );
      
          youtube[i].addEventListener( "click", function() {

            var iframe = document.createElement( "iframe" );

                iframe.setAttribute( "frameborder", "0" );
                iframe.setAttribute( "allowfullscreen", "" );
                iframe.setAttribute( "src", "https://www.youtube.com/embed/"+ this.dataset.embed +"?rel=0&showinfo=0&autoplay=1" );

                this.innerHTML = "";
                this.appendChild( iframe );
          } );  
    };

    } )();
</script> 
/*=======VIDEO YOUTUBE=======*/

.video .youtube {
    background-color: #000;
    position: relative;
    padding-top: 56.25%;
    overflow: hidden;
    cursor: pointer;
}
.youtube img {
    width: 100%;
    top: -16.82%;
    left: 0;
    opacity: 0.7;
}
.youtube .play-button {
    width: 90px;
    height: 60px;
    background-color: #333;
    box-shadow: 0 0 30px rgba( 0,0,0,0.6 );
    z-index: 1;
    opacity: 0.8;
    border-radius: 6px;
}
.youtube .play-button:before {
    content: "";
    border-style: solid;
    border-width: 15px 0 15px 26.0px;
    border-color: transparent transparent transparent #fff;
}
.youtube img,
.youtube .play-button {
    cursor: pointer;
}
.youtube img,
.youtube iframe,
.youtube .play-button,
.youtube .play-button:before {
    position: absolute;
}
.youtube .play-button,
.youtube .play-button:before {
    top: 50%;
    left: 50%;
    transform: translate3d( -50%, -50%, 0 );
}
.youtube iframe {
    height: 100%;
    width: 100%;
    top: 0;
    left: 0;
}
.video {
    display: block;
    width: 600px;
    margin: 0 auto 35px auto;
    max-width: 100%;
}
/*=======CADRE DE LA VIDEO YOUTUBE=======*/
.video .wrapper {
    border: 5px solid black;
    width: 100%;
}
/*=======CADRE DE LA VIDEO=======*/
.video .wrapper {
    width: 100%;
    padding: 7.5px 7.5px;
    border: 1px solid #C9C9C9;
    -webkit-box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19),
    0 6px 6px rgba(0, 0, 0, 0.23);
    -moz-box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19),
    0 6px 6px rgba(0, 0, 0, 0.23);
    -ms-box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19),
    0 6px 6px rgba(0, 0, 0, 0.23);
    -o-box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19),
    0 6px 6px rgba(0, 0, 0, 0.23);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19),
    0 6px 6px rgba(0, 0, 0, 0.23);
}
.video .wrapper {
    -webkit-transform: rotate(-2deg);
    -moz-transform: rotate(-2deg);
}
/* Rotate all even images 2 degrees */
.video .wrapper:nth-child(even) a img {
    -webkit-transform: rotate(2deg);
    -moz-transform: rotate(2deg);
}
/* Don't rotate every third image, but offset its position */
.video .wrapper:nth-child(3n) a img {
    -webkit-transform: none;
    -moz-transform: none;
    position: relative;
    top: -5px;
}
/* Rotate every fifth image by 5 degrees and offset it */
.video .wrapper:nth-child(5n) a img {
    -webkit-transform: rotate(5deg);
    -moz-transform: rotate(5deg);
    position: relative;
    right: 5px;
}
/* Keep default rotate for every eighth, but offset it */
.video .wrapper:nth-child(8n) a img {
    position: relative;
    top: 8px;
    right: 5px;
}
/* Keep default rotate for every eleventh, but offset it */
.video .wrapper:nth-child(11n) a img {
    position: relative;
    top: 3px;
    left: -5px;
}
.video .wrapper:hover {
    -webkit-transform: scale(1.25);
    -moz-transform: scale(1.25);
    position: relative;
    z-index: 5;
}
.video .wrapper {
    -webkit-transition: -webkit-transform .15s linear;
    -webkit-box-shadow: 0 3px 6px rgba(0, 0, 0, .25);
    -moz-box-shadow: 0 3px 6px rgba(0, 0, 0, .25);
}
/* On hover, darken the shadows a bit */
.video .wrapper {
    -webkit-box-shadow: 0 3px 6px rgba(white);
    -moz-box-shadow: 0 3px 6px rgba(white);
}
<div class="video" data-id="abn-w2Gs54o">
    <div class="wrapper">
        <div class="youtube" data-embed="abn-w2Gs54o">
            <div class="play-button"></div>
        </div>
    </div>
</div>

Could you help me understand why? Best regards enter image description here

  • Try to simplify at most https://www.jobcool.fr/single.html [as I already said](https://stackoverflow.com/q/73512229/7123660) in order to find the problem as [your code works fine on my website](https://lemnoslife.com/BEN/73579891.html). – Benjamin Loison Sep 02 '22 at 10:50
  • Thanks Benjamin for your response. I see the video showing up on your site. But I don't understand why it doesn't appear on mine. From my mac, the videos are not working. Even when I watch from my samsung phone the videos do not appear. I do not know why. – Pourmonmec France Sep 03 '22 at 16:13
  • As [your whole webpage works correctly on my website](https://lemnoslife.com/BEN/73579891/single.html), please just upload [the minimal reproduceable example](https://lemnoslife.com/BEN/73579891.html) on your website and share here the URL to this minimal webpage. – Benjamin Loison Sep 03 '22 at 16:52
  • hi benjamin, here is the [link](https://www.jobcool.fr/single.html) with the minimal reproduceable example on my site: – Pourmonmec France Sep 04 '22 at 17:52
  • It seems that your web server has some settings making the external content unable to load, the JavaScript console notifies only on your webpage that: `Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).`. I am not keen on such things, do you have any `.htaccess` in the folder of https://www.jobcool.fr/ ? Maybe just have a look to [this question](https://stackoverflow.com/q/37298608/7123660). – Benjamin Loison Sep 04 '22 at 18:04
  • Hi Benfamin, here is my htaccess code: – Pourmonmec France Sep 04 '22 at 21:54
  • Note that you haven't sent the `.htaccess` content. – Benjamin Loison Sep 04 '22 at 22:14
  • Hi Benjamin, here is my htaccess [link](https://www.jobcool.fr/htaccess.html) – Pourmonmec France Sep 04 '22 at 23:11
  • I have the following line in my htaccess ( Header set Content-Security-Policy "script-src 'self' https://www.google.com" ) but I have already used it for another of my sites which has the same type of video on the index page like pourmonmec.com – Pourmonmec France Sep 04 '22 at 23:15
  • What about removing ` Header set Content-Security-Policy "script-src 'self' google.com" ` as it is the source of your problem (as I added it to my `.htaccess` and now [my webpage faces the same problem as you](https://lemnoslife.com/BEN/73579891.html)) ? – Benjamin Loison Sep 04 '22 at 23:38
  • Cool! It's ok. I removing the code in my Htaccess file and the videos appear on my site. Thanks a lot for your help Benjamin. – Pourmonmec France Sep 05 '22 at 16:12
  • I have a last question: on this page link](https://jobcool.fr/Travailler-dans-la-nature-sans-diplome-en-devenant-fossoyeur-ou-fossoyeuse-et-en-ayant-un-emploi-bien-paye-sans-diplome-dans-un-cimetiere.html), the javascript does not retrieve the image of the first video placed at the top of the page. Do you have a solution to make it appear? Best regards. – Pourmonmec France Sep 05 '22 at 17:59
  • 1
    StackOverflow questions aren't a chat room for different problems, please ask another question on StackOverflow and pay attention again to produce a minimal reproduceable standalone example of your problem, otherwise as your webpage is having a lot of JavaScript errors (have a look at your web browser content when being on the webpage). – Benjamin Loison Sep 05 '22 at 18:44

0 Answers0