{"id":18286363,"url":"https://github.com/sidp/iframes","last_synced_at":"2025-04-09T06:25:04.376Z","repository":{"id":57160173,"uuid":"122605556","full_name":"sidp/iframes","owner":"sidp","description":"Gives an iframe control of its parent window.","archived":false,"fork":false,"pushed_at":"2018-06-15T09:54:03.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T05:58:40.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sidp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T10:13:32.000Z","updated_at":"2018-06-15T09:54:04.000Z","dependencies_parsed_at":"2022-08-24T14:42:22.345Z","dependency_job_id":null,"html_url":"https://github.com/sidp/iframes","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidp%2Fiframes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidp%2Fiframes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidp%2Fiframes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidp%2Fiframes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sidp","download_url":"https://codeload.github.com/sidp/iframes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247988974,"owners_count":21029201,"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-11-05T13:19:54.630Z","updated_at":"2025-04-09T06:25:04.323Z","avatar_url":"https://github.com/sidp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @sidp/iframes\n\nGive control of the parent window in an iframed page. Works cross-domain by utilizing the postMessage API. It is under development and things might still break.\n\n## API\n\nIn the parent document:\n\n```html\n\u003ciframe src=\"https://[...]\" id=\"iframe\"\u003e\u003c/iframe\u003e\n```\n\n```js\nimport { setup } from '@sidp/iframes';\nconst iframe = setup(document.getElementById('iframe'));\n```\n\nIn the iframed document:\n\n```js\nimport { parentWindow, iframe } from '@sidp/iframes';\n```\n\nThe `parentWindow` object contains functions referring to the parent window and and `iframe` contains functions referring ot the iframe element in the parent document.\n\n### Set the scroll position\n\n```js\nparentWindow.scrollTo(x, y);\n```\n\nThe arguments must be provided as numbers. They are interpreted as pixel values.\n\n### Get the scroll position\n\nGet the current scroll position of the parent window. The returned number is a pixel value. The functions take no arguments.\n\n```js\nparentWindow.scrollX(); // -\u003e 0\nparentWindow.scrollY(); // -\u003e 0\n```\n\n### Get and set the size of the iframe\n\nGet and set the height and width of the iframe. Numbers are interpreted as pixels and strings as css values.\n\n```js\niframe.height(); // -\u003e 620\niframe.height('100vh');\n```\n\n### Position of the iframe in the parent document\n\nThe following functions return the position of the iframe in the parent document. The returned number is a pixel value. The functions take no arguments.\n\n```js\niframe.top() // -\u003e 360\niframe.left() // -\u003e 16\niframe.right() // -\u003e 16\niframe.bottom(): // -\u003e 840\n```\n\nThe following funtions return the position of the iframe relative to the viewport. The returned number is a pixel value. The functions take no arguments.\n\n```js\niframe.viewport.top(); // -\u003e 100\niframe.viewport.left(); // -\u003e 16\niframe.viewport.right(); // -\u003e 16\niframe.viewport.bottom(); // -\u003e 200\n```\n\n### Listen to events (not implemented yet)\n\nIn the parent document:\n\n```js\nimport { setup } from '@sidp/iframes';\nconst iframe = setup(document.getElementById('iframe'));\n\niframe.on('resize', ({ width, height }) =\u003e {\n\tconsole.log('the iframe resized itself', width, height);\n});\n\niframe.on('scroll', ({ x, y }) =\u003e {\n\tconsole.log('iframe scrolled the window to', x, y);\n});\n```\n\nIn the iframed document:\n\n```js\nimport { parent, iframe } from '@sidp/iframes';\nparent.on('init', () =\u003e {\n\tconsole.log(\n\t\t'The parent document initialized the iframe script for this iframe'\n\t);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidp%2Fiframes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidp%2Fiframes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidp%2Fiframes/lists"}