0.1.4 • Published 6 years ago

nested-iframe v0.1.4

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

nested-iframe

GitHub stars

Recursively find a nested iframe

Please ★ this repo if you found it useful ★ ★ ★

Features

  • Asynchronously waits for iframe to load
  • Optional timeout
  • Optionally find nested iframe synchronously

Installation

npm install --save nested-iframe

Dependencies

Usage

Example 1

Waits for all iframes to load

The deepest iframe is returned

import nestedIframe from 'nested-iframe';

nestedIframe([
  '#parentIframe',
  '#childIframe',
  '#grandchildIframe'
]).then((grandchildIframe) => {
  grandchildIframe.contentDocument.body.innerHTML = 'Hello, world!';
});

Example 2

Optional timeout at 5 seconds

The deepest iframe that is loaded is returned

import nestedIframe from 'nested-iframe';

nestedIframe([
  '#parentIframe',
  '#childIframe',
  '#grandchildIframe'
], { timeout: 5000 }).then((grandchildIframe) => {
  grandchildIframe.contentDocument.body.innerHTML = 'Hello, world!';
});

Example 3

Optional timeout at 5 seconds

Throws an error if timeout

import nestedIframe from 'nested-iframe';

nestedIframe([
  '#parentIframe',
  '#childIframe',
  '#grandchildIframe'
], {
  timeout: 5000,
  error: true
}).then((grandchildIframe) => {
  grandchildIframe.contentDocument.body.innerHTML = 'Hello, world!';
}).catch((err) => {
  console.error(err);
});

Example 4

Does not wait for iframes to load

The deepest iframe that is loaded is returned (probably the parentIframe)

import { nestedIframeSync } from 'nested-iframe';

const grandchildIframe = nestedIframe([
  '#parentIframe',
  '#childIframe',
  '#grandchildIframe'
]);
grandchildIframe.contentDocument.body.innerHTML = 'Hello, world!';

Example 5

Does not wait for iframes to load

Throws an error if deepest iframe not loaded

import { nestedIframeSync } from 'nested-iframe';

try {
  const grandchildIframe = nestedIframe([
    '#parentIframe',
    '#childIframe',
    '#grandchildIframe'
  ], { error: true });
  grandchildIframe.contentDocument.body.innerHTML = 'Hello, world!';
} catch(err) {
  console.error(err);
}

Support

Submit an issue

Contributing

Review the guidelines for contributing

License

MIT License

Jam Risser © 2018

Changelog

Review the changelog

Credits

Support on Liberapay

A ridiculous amount of coffee ☕ ☕ ☕ was consumed in the process of building this project.

Add some fuel if you'd like to keep me going!

Liberapay receiving Liberapay patrons

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago