Recursively find a nested iframe
Please ★ this repo if you found it useful ★ ★ ★
- Asynchronously waits for iframe to load
- Optional timeout
- Optionally find nested iframe synchronously
npm install --save nested-iframe
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!';
});
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!';
});
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);
});
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!';
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);
}
Submit an issue
Review the guidelines for contributing
Jam Risser © 2018
Review the changelog
- Jam Risser - Author
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!