Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 5485

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 27, 20242024-11-27T09:43:07+00:00 2024-11-27T09:43:07+00:00

How to make a rickroll website

  • 61k
video autoplayer using vanilla Javascript and CSS

Description :

It might seem easy to make this kinds of a website , just embed a video from YouTube and play it when the user comes to our website but the problem is
autoplay meme

Problem :

To autoplay a video on the web on any device , the audio of the video must be muted . This is the autoplay policy followed by almost all browsers

The Autoplay Policy launched in Chrome 66 for audio and video elements and is effectively blocking roughly half of unwanted media autoplays in Chrome. For the Web Audio API, the autoplay policy launched in Chrome 71. This affects web games, some WebRTC applications, and other web pages using audio features.

New behaviors

As you may have noticed, web browsers are moving towards stricter autoplay policies in order to improve the user experience, minimize incentives to install ad blockers, and reduce data consumption on expensive and/or constrained networks. These changes are intended to give greater control of playback to users and to benefit publishers with legitimate use cases.

Chrome's autoplay policies are simple but this generally holds true for all browsers:

  1. Muted autoplay is always allowed.
  2. Autoplay with sound is allowed if:
  3. The user has interacted with the domain (click, tap, etc.).
  4. On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.
  5. The user has added the site to their home screen on mobile or installed the PWA on desktop.
  6. Top frames can delegate autoplay permission to their iframes to allow autoplay with sound. This make it really difficult to catch people offguard and rickrolling them as soon as they open up our website

Solution :

Did you catch the 3rd point ? Why don't we just fake an interaction ?

tl;dr-> just ask for cookies and play the rick roll when they clicks “accept cookies” lol .

A workaround to this also used by many other rick roll generators is asking the user for cookies , when the user clicks on “accept cookies” they are actually clicking on a button that will play the rickroll

This way we have the permission of the user to play the video without having their permission

Firstly I have created a simple sort of a landing page that asks the user for permission with the accept button

My “landing page” asking for cookies is overlayed over the rick roll video so that it's hidden

  <div class="cookies" id="permission">         <p>This website uses cookies to provide necessary website functionality, improve your experience and analyze our traffic.            <br>By using our website, you agree to our Privacy Policy and our Cookies Policy.         </p>   
Enter fullscreen mode Exit fullscreen mode

We need to include the script for the YouTube API using

  <script id="iframe-demo" src="https://www.youtube.com/iframe_api"></script>****   
Enter fullscreen mode Exit fullscreen mode

I have added an event listener listening for a click from the user on the button which then unmutes the previously paused video and the video starts playing when the button is clicked

  // button      cookieConsent.addEventListener('click', () => {         player.seekTo(0); //  player = new YT.Player('video-frame');         player.unMute();         });   
Enter fullscreen mode Exit fullscreen mode

The accept cookies button is actually connect to the hide() function in my JavaScript file which hides the overlay on click of the button

  <button onclick="hide()" id="accept">Accept</button></center>   
Enter fullscreen mode Exit fullscreen mode

I have also disabled any control over the video , you cannot really take off the pause and YouTube logo from the embed but again there is a workaround:

I have taken the iframe embed and in my css and made it so that the pointer cannot do anything over the video

  .ytplayer{  pointer-events: none; }   
Enter fullscreen mode Exit fullscreen mode

final result (satvik.ninja/website)

beginnersjavascripttutorialwebdev
  • 0 0 Answers
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.