Firing Lightning Events from Non-Lightning Code

You can fire Lightning events from JavaScript code outside a Lightning app. For example, your Lightning app might need to call out to some non-Lightning code, and then have that code communicate back to your Lightning app once it's done.

For example, you could call external code that needs to log into another system and return some data to your Lightning app. Let's call this event mynamespace:externalEvent. You'll fire this event when your non-Lightning code is done by including this JavaScript in your non-Lightning code.

var myExternalEvent;
    if(window.opener.$A &&
      (myExternalEvent = window.opener.$A.get("e.mynamespace:externalEvent"))) {
         myExternalEvent.setParams({isOauthed:true});
         myExternalEvent.fire();
       }

window.opener.$A.get() references the master window where your Lightning app is loaded.