Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iframe-messenger

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iframe-messenger

iframe messenger

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

iframeMessenger

postMessage interface allowing for the resizing of containing iframe and link navigation of the parent window.

Latest CDN version

http://interactive.guim.co.uk/libs/iframe-messenger/iframeMessenger.js

Usage

Include the library within your page or application via <script> or require(). Call a method. You'll probably want to call enableAutoResize().

Auto-resize example:

<script src="//interactive.guim.co.uk/libs/iframe-messenger/iframeMessenger.js"></script>
<script>
    iframeMessenger.enableAutoResize();
</script>

Getting parent's URL hash fragment example:

<script src="//interactive.guim.co.uk/libs/iframe-messenger/iframeMessenger.js"></script>
<script>
    function logParentHashFragment(locationObj) {
        console.log(locationObj.hash);
    }

    iframeMessenger.getLocation(logParentHashFragment);
</script>

Send all links to parent window example:

<script src="//interactive.guim.co.uk/libs/iframe-messenger/iframeMessenger.js"></script>
<script>
    var links = document.querySelectorAll('a');
    for(var i = 0; i < links.length; i++) {
        links[i].addEventListener('click', function(event) {
            event.preventDefault();
            iframeMessenger.navigate(this.href);
        }, false);
    }
</script>

Methods

.enableAutoResize(options)

Update iframe wrapper to match document height. Optional options (object) can be provided.

NOTE: absoluteHeight checks the position of every element on the page, this has a significant performance impact.

{
    absoluteHeight: false // Check absolute height of every element, slow!
}
.resize(height)

(optional) height : INT or percentage eg '20%' Specify a height for the iframe wrapper. If no height is specified the height of the current document is sent.

.getLocation(callback)

Ask parent page for location information and executes callback passing along an object containing parent's document.location information.

Sample of returned location object:

{
    hash: "#myhash",
    host: "example.com:8080",
    hostname: "exaple.com",
    href: "http://example.com:8080/test.html?query=test#myhash",
    origin: "http://example.com:8080",
    pathname: "/test.html",
    port: "8080",
    protocol: "http:"
    search: "?query=test",
    type: "get-location"            // for iframeMessenger usage
    id: "iframeMessenger:ceprg"     // for iframeMessenger usage
}
.navigate(url)

Navigate parent window to specified URL (string)

.scrollTo(x, y)

Sends request to scroll the parent page to a specified x, y position.

.getPositionInformation(callback)

Ask parent page for position information and execute callback upon return post message.

Sample of returned position data object:

{
    'iframeTop':    300,    // iframe.getBoundingClientRect().top,
    'innerHeight':  620,    // window.innerHeight,
    'innerWidth':   960,    // window.innerWidth,
    'pageYOffset':  90      // window.pageYOffset
}

Similar projects

Changelog

0.2.7

  • Added support for AdobeEdge content
  • New method for wrapping content using ::before and ::after CSS
  • More consistent height calculations across browsers
  • Listen for window 'load' before auto resizing
  • Lots more tests

0.2.6

  • Added .getLocation(callback) for retrieving parent location information
  • Added postMessage id to identify returning messages
  • Updated height calculation using max of several different readings
  • Fixed tests

0.2.5

  • Listen for image load events and trigger resize
  • More sensible way for calculating height
  • Removed sending of 'href' for validation

0.2.4

  • Remove trailing slash from location.href to prevent validation errors
  • Check received postMessage validity to prevent unsolicited responses

0.2.3

  • Added .getPositionInformation(callback) and .scrollTo(x, y)
  • More tests

0.2.2

  • Send iframe location.href to identify it to parent listener
  • Added unit tests

0.2.1:

  • Added absoluteHeight option to auto-resize to handle absolute absolute positioned elements

0.2.0:

  • Added DOM modification detection with setInterval fallback
  • Replaced hard-coded margin with getComputedStyle() values

0.1.0:

  • Initial release.

Notes

HTML Document height via JavaScript research

FAQs

Package last updated on 16 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc