npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postmessage-polyfill

v1.0.0

Published

window postmessage plugin =========================

Downloads

1,005

Readme

window postmessage plugin

Modern browsers now support cross-window/cross-domain/cross-origin messaging through window.postMessage.

postmessage is a simple wrapper for window.postMessage and the window message event, for those who wish to use this feature in a more jQuery-like way.

postmessage falls back to window location hash polling for browsers that do not support window.postMessage (i.e., IE7).

postmessage allows messaging back and forth using JSON where window.postMessage only allows simple string-based messages.

postmessage also allows for complete request/response roundtrips using success/error callbacks modeled after jQuery.ajax.

postmessage is tested on Safari 4, WebKit (Nightlies), Chrome 4, Firefox 3, IE8, IE7 and Opera 10.10.

API

pm(options)

    Send postmessage.

    options:Map (Required)
            A set of key/value pairs that configure the postmessage:

            target:Window (Required)
                    The target window to send the postmessage.

            type:String (Required)
                    The postmessage type. The postmessage will be
                    dispatched to handler(s) bound to postmessages of this 
                    type.

            data:Object (Required)
                    The postmessage data to be sent.

            success:Function (Optional)
                    A function to be called if the postmessage succeeds. 
                    The function gets passed the object returned by the 
                    postmessage handler.

            error:Function (Optional)
                    A function to be called if the postmessage fails. The 
                    function gets passed the object thrown (Exception) by 
                    the postmessage handler.

            origin:String (Optional)
                    The target origin for the postmessage to be 
                    dispatched, either as the literal string "*"
                    (indicating no preference) or as a URI. The 
                    postmessage will only be dispatched if the scheme, 
                    hostname and port match the target origin. 
                    Default is "*".

            url:String (Optional)
                    Required if window.postMessage is not available or 
                    using location hash. The current url of the target 
                    window you are sending the postmessage to. This is 
                    required for setting the location hash of the target 
                    window since you may not have access to reading the 
                    target window.location. 

            hash:Boolean (Optional)
                    You can force passing postmessages via the target 
                    window location hash by setting this to true.

pm.bind(type, fn, [origin], [hash])

    Bind postmessage handler on the current window.

    type:String (Required)
            The postmessage type to bind to.

    fn:Function (Required)
            The postmessage handler. A function to execute each time the 
            postmessage type is received. The function gets passed the 
            postmessage data.

    origin:String (Optional)
            A URI specifying the origin of the postmessage. If specified, 
            the postmessage handler will only be executed if the 
            postmessage is received from the same origin matching the 
            scheme, hostname and port. Otherwise, the postmessage sender 
            will be notified through it's error callback of the origin 
            mismatch:

                {
                    "message": "postmessage origin mismatch",
                    "origin": [
                        "http://www.abc.com",
                        "http://www.xyz.com"
                    ]
                }

            You can set this globally. However, the origin specified in 
            the bind method will take precedence.

                pm.origin = "http://www.xyz.com";

    hash:Boolean (Optional)
            You can force location hash polling to check for postmessages 
            by setting this to true. This is required only if you are 
            (forcefully) passing postmessages via the location hash.

pm.unbind([type], [fn])

    Remove a previously-attached postmessage handler from the current 
    window. If type is not specified, all postmessage handlers will be 
    removed.

    type:String (Optional)
            The postmessage type to unbind from. If only the type is 
            specified all handlers of this type will be removed.

    fn:Function (Optional)
            The function that is to be no longer executed.

For examples and more:

http://postmessage.freebaseapps.com