I'm using EasyXDM to handle cross-domain communication so that the parent knows both the size of the child and the location of the child. I've got the sizing working. The issue is when I navigate while inside the iframe I want to push the location back up to the parent.
The issue is that when I change page that the socket fails to get created again, giving me VM87 Core.js:324 Uncaught Error: url is undefined or empty.
Anyone else run into this?
Parent(consumer):
<script language="javascript">
(function () {
// CTOR has side effect of creating globals for socket
var socket = new easyXDM.Socket({
remote: "@(Model.Url)" + document.location.hash,
container: $("#pluginFrame")[0],
onMessage: function (message, origin) {
var messageAsObject = JSON.parse(message);
if (messageAsObject.height) {
$("#pluginFrame iframe").height(messageAsObject.height);
}
if (messageAsObject.path) {
document.location.hash = messageAsObject.path;
}
},
onReady: function() {
console.log("Shell Socket Ready");
$("#pluginFrame iframe").width("100%");
}
});
})();
</script>
Child(producer) Razor Layout
<script language="javascript">
(function () {
debugger;
var socket = new easyXDM.Socket({
onReady: function () {
console.log("eBox Ready");
socket.postMessage(JSON.stringify({
height: $(".body-content").outerHeight(),
path: document.location.pathname
}));
}
});
$("body-content")
.on("change",
function () {
socket.postMessage(JSON.stringify({
height: $(".body-content").outerHeight()
}));
});
$(document.location.pathname)
.on("change",
function () {
socket.postMessage(JSON.stringify({
path: document.location.pathname
}));
});
socket.postMessage(JSON.stringify({
path: document.location.pathname
}));
})();
</script>
From everything I've seen there's no possible way to do what I'm after. It seems that the only solution for the problems I was ultimately trying to solve, pushing routing into the location hash of the parent, is to use the double iframe approach mentioned here.