View on GitHub

Pm.js

A simple, effective, and secure postMessage solution for your websites. Goodnight.

Download this project as a .zip file Download this project as a tar.gz file

PM.js

PM.js is a postMessage wrapper for client-side Javascript that allows two websites from different domains, protocols, and ports to communicate with eachother and execute javascript functions on the other website.

postMessage is a RPC-style Javascript messaging system that's in use by Google, Facebook, Twitter, Disney, and many other websites. It's also used for advertisers or in ad tracking such as for Google's adsense. Anywhere you might need two websites to communicate with eachother through client-side code, postMessage can be used and PM.js can make your life easier.

Examples

RPC-up - Visible iframe to parent

A common theme in iframes is for developers to want the iframe to communicate with the parent window when something has happened. Perhaps a user has logged in or pressed a button within the iframe. This is may be used for something like an OAuth login screen, such as Facebook's login, or Google's.

The assumption here is that the iframe website knows what the URL is of the parent website. This is usually accomplished by feeding the iframe website the URL in a query string, such as

http://logindomain.com/iframepage.html?referrer=http%3A%2F%2Fouterdomain.com%2Flogin.html
Notice how the URL for the main domain's login page is in the "referrer" query string. This allows the iframe's webpage to know what domain to communicate with.

RPC-down - Child functions

Round trips

Exceptions

Authors and Contributors

Allan Bogh (@ajbogh) - Creator and lead developer

Support or Contact

Having trouble with Pm.js? Submit an issue so we can help you can your question can help others https://github.com/ajbogh/PM.js/issues or contact Allan Bogh and we’ll help you sort it out.