{"id":13432453,"url":"https://github.com/npm-dom/iframe","last_synced_at":"2025-03-16T23:31:24.322Z","repository":{"id":6770721,"uuid":"8017531","full_name":"npm-dom/iframe","owner":"npm-dom","description":"higher level api for creating and using iframes in browsers","archived":false,"fork":false,"pushed_at":"2016-04-09T01:18:24.000Z","size":12,"stargazers_count":40,"open_issues_count":1,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-05T03:33:47.628Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://npm.im/iframe","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm-dom.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-04T22:14:29.000Z","updated_at":"2024-07-26T21:08:45.000Z","dependencies_parsed_at":"2022-09-15T14:11:56.748Z","dependency_job_id":null,"html_url":"https://github.com/npm-dom/iframe","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-dom%2Fiframe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-dom%2Fiframe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-dom%2Fiframe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm-dom%2Fiframe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm-dom","download_url":"https://codeload.github.com/npm-dom/iframe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243949921,"owners_count":20373655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:01:11.804Z","updated_at":"2025-03-16T23:31:23.962Z","avatar_url":"https://github.com/npm-dom.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# iframe\n\nhigher level api for creating and removing iframes in browsers\n\n[![browser support](https://ci.testling.com/npm-dom/iframe.png)](https://ci.testling.com/npm-dom/iframe)\n\n[![NPM](https://nodei.co/npm/iframe.png)](https://nodei.co/npm/iframe/)\n\n## usage\n\nuse with [browserify](http://browserify.org)\n\n```\nnpm install iframe\n```\n\n```javascript\nvar iframe = require('iframe')\n\n// creates a new iframe and appends it to the container\nframe = iframe({ container: document.querySelector('#container') , body: \"hi\" })\n\n// completely removes previous iframe from container and generates a new one\nframe.setHTML({ body: \"bye\" })\n```\n\n## options\n\nyou can pass this into the constructor or `setHTML`\n\n```\n{\n  name: name of the iframe,\n  src: if src url is passed in use that (this mode ignores body/head/html options),\n  body: string contents for `\u003cbody\u003e`\n  head: string contents for `\u003chead\u003e`\n  html: string contents for entire iframe\n  container: (constructor only) dom element to append iframe to, default = document.body\n  sandboxAttributes: array of capability flag strings, default = ['allow-scripts']\n  scrollingDisabled: (constructor only) boolean for the iframe scrolling attr\n}\n```\n\nyou can also just pass in a string and it will be used as `{html: 'yourstring'}`\n\n### security\n\nby default the sandbox attribute is set with 'allow-scripts' enabled. pass in an array of capability flag strings. [Available flags](http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/):\n```\nallow-forms allows form submission.\nallow-popups allows (shock!) popups.\nallow-pointer-lock allows (surprise!) pointer lock.\nallow-same-origin allows the document to maintain its origin; pages loaded from https://example.com/ will retain access to that origin’s data.\nallow-scripts allows JavaScript execution, and also allows features to trigger automatically (as they’d be trivial to implement via JavaScript).\nallow-top-navigation allows the document to break out of the frame by navigating the top-level window.\n```\n\n## gotchas\n\niframes are weird. here are some things I use to fix weirdness:\n\n### loading javascript into iframes\n\n```javascript\n// setTimeout is because iframes report inaccurate window.innerWidth/innerHeight, even after DOMContentLoaded!\nvar body = '\u003cscript type=\"text/javascript\"\u003e setTimeout(function(){' + javascriptCodeHere + '}, 0)\u003c/script\u003e'\n```\n\n### getting rid of dumb iframe default styles\n\n```javascript\nvar head = \"\u003cstyle type='text/css'\u003e html, body { margin: 0; padding: 0; border: 0; } \u003c/style\u003e\"\n```\n\n## license\n\nBSD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm-dom%2Fiframe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm-dom%2Fiframe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm-dom%2Fiframe/lists"}