Fix irame message handling
This commit is contained in:
parent
e9917737de
commit
1c93d924de
|
@ -1,6 +1,6 @@
|
|||
<html>
|
||||
|
||||
<iframe src="./index.html" style="border: 1px solid red; width: 95%; height: 95%" id="meshviewer-embedded"></iframe>
|
||||
<script type="text/javascript" src="./embed.js" />
|
||||
<script type="text/javascript" src="./embed.js"></script>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -11,10 +11,6 @@
|
|||
}
|
||||
|
||||
function updateIframeHash() { // see https://gist.github.com/manufitoussi/7529fa882ff0b737f257
|
||||
if(iframe.contentWindow.location.host !== "") {
|
||||
// iframe already loaded.
|
||||
iframe.contentWindow.location.hash = window.location.hash;
|
||||
} else {
|
||||
// iframe is just starting.
|
||||
var newHash = window.location.hash;
|
||||
var srcStr = iframe.getAttribute('src');
|
||||
|
@ -22,11 +18,10 @@
|
|||
var href = words[0];
|
||||
var newSrc = href + newHash;
|
||||
iframe.setAttribute('src', newSrc);
|
||||
}
|
||||
};
|
||||
|
||||
updateIframeHash();
|
||||
iframe.contentWindow.addEventListener("message", (event) => {
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event && event.data && event.data.hash) {
|
||||
window.location.replace(event.data.hash);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ define(['moment', 'utils/router', 'leaflet', 'gui', 'helper', 'utils/language'],
|
|||
}
|
||||
|
||||
window.onhashchange = function () {
|
||||
window.postMessage({hash: window.location.hash}, '*');
|
||||
parent.postMessage({hash: window.location.hash}, '*');
|
||||
};
|
||||
|
||||
var language = new Language();
|
||||
|
|
Reference in New Issue