Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mvsde/iframe-click-to-play

On-demand loading for iframes to conform with laws like GDPR.
https://github.com/mvsde/iframe-click-to-play

click-to-play gdpr iframe

Last synced: 30 days ago
JSON representation

On-demand loading for iframes to conform with laws like GDPR.

Awesome Lists containing this project

README

        

# 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.

[Demos →](https://iframe-click-to-play.fynn.be)

## Installation

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

## Usage

### Markup

Rename the `src` attribute of the `` 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 ``

[Demo for the standalone variant →](https://iframe-click-to-play.fynn.be/standalone.html)

```html


YouTube Video Embed


Click to load the embedded YouTube video.


Load video

```

#### `` within a container

[Demo for the container variant →](https://iframe-click-to-play.fynn.be/container.html)

The `` can be nested inside a container. The script automatically searches for the first descendant ``.

```html




YouTube Video Embed


Click to load the embedded YouTube video.


Load video

```

### JavaScript

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

```js
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()
```