New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@mvsde/iframe-click-to-play

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mvsde/iframe-click-to-play

Some ``s might save cookies or do other kinds of tracking. This isn't allowed under GDPR law without prior consent from the user. A “click-to-play” solution helps with this situation.

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

iframe Click-to-Play

Some <iframe>s might save cookies or do other kinds of tracking. This isn't allowed under GDPR law without prior consent from the user. A “click-to-play” solution helps with this situation.

Demos →

Installation

npm install @mvsde/iframe-click-to-play

Usage

Markup

Rename the src attribute of the <iframe> to data-src This makes sure no external content gets loaded without prior consent. A fallback element is required which may have arbitrary content. The trigger button can be part of the fallback element, but doesn’t need to be.

Standalone <iframe>

Demo for the standalone variant →

<iframe
  class="iframe"
  data-src="https://www.youtube.com/embed/OrxmtDw4pVI"
  width="960"
  height="540"
></iframe>

<div class="fallback">
  <h2>YouTube Video Embed</h2>
  <p>Click to load the embedded YouTube video.</p>
  <button class="trigger">Load video</button>
</div>
<iframe> within a container

Demo for the container variant →

The <iframe> can be nested inside a container. The script automatically searches for the first descendant <iframe>.

<div class="iframe">
  <iframe
    class="iframe"
    data-src="https://www.youtube.com/embed/OrxmtDw4pVI"
    width="960"
    height="540"
  ></iframe>
</div>

<div class="fallback">
  <h2>YouTube Video Embed</h2>
  <p>Click to load the embedded YouTube video.</p>
  <button class="trigger">Load video</button>
</div>

JavaScript

Select the <iframe> or the element containing it, the fallback element, and the trigger button. Create a new IframeClickToPlay instance.

import { IframeClickToPlay } from '@mvsde/iframe-click-to-play'

const iframe = document.querySelector('.iframe')
const fallback = document.querySelector('.fallback')
const trigger = document.querySelector('.trigger')

new IframeClickToPlay({ iframe, fallback, trigger }).init()

FAQs

Package last updated on 28 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc