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