Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Resolve 'frame is null' errors #269

Merged
merged 1 commit into from
Mar 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/stack/PostMessageTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ easyXDM.stack.PostMessageTransport = function(config){
pub.up.incoming(event.data.substring(config.channel.length + 1), origin);
}
}


/**
* This adds the listener for messages when the frame is ready.
* @private
* @param {Object} event The messageevent
*/
// add the event handler for listening
function _window_waitForReady(event){
if (event.data == config.channel + "-ready") {
// #ifdef debug
trace("firing onReady");
// #endif
// replace the eventlistener
callerWindow = ("postMessage" in frame.contentWindow) ? frame.contentWindow : frame.contentWindow.document;
un(window, "message", _window_waitForReady);
on(window, "message", _window_onMessage);
setTimeout(function(){
pub.up.callback(true);
}, 0);
}
};

return (pub = {
outgoing: function(message, domain, fn){
Expand All @@ -97,6 +119,7 @@ easyXDM.stack.PostMessageTransport = function(config){
// #ifdef debug
trace("destroy");
// #endif
un(window, "message", _window_waitForReady);
un(window, "message", _window_onMessage);
if (frame) {
callerWindow = null;
Expand All @@ -110,22 +133,7 @@ easyXDM.stack.PostMessageTransport = function(config){
// #endif
targetOrigin = getLocation(config.remote);
if (config.isHost) {
// add the event handler for listening
var waitForReady = function(event){
if (event.data == config.channel + "-ready") {
// #ifdef debug
trace("firing onReady");
// #endif
// replace the eventlistener
callerWindow = ("postMessage" in frame.contentWindow) ? frame.contentWindow : frame.contentWindow.document;
un(window, "message", waitForReady);
on(window, "message", _window_onMessage);
setTimeout(function(){
pub.up.callback(true);
}, 0);
}
};
on(window, "message", waitForReady);
on(window, "message", _window_waitForReady);

// set up the iframe
apply(config.props, {
Expand Down