Total Complexity | 7 |
Complexity/F | 2.33 |
Lines of Code | 35 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | (function() { |
||
2 | |||
3 | var iframe=document.getElementById("meshviewer-embedded") |
||
4 | if (!iframe) { |
||
5 | console.log("IFrame 'meshviewer-embedded' not found") |
||
|
|||
6 | return; |
||
7 | } |
||
8 | if (!iframe.contentWindow) { |
||
9 | console.log("Element 'meshviewer-embedded' seems not to be a valid iframe") |
||
10 | return; |
||
11 | } |
||
12 | |||
13 | function updateIframeHash() { // see https://gist.github.com/manufitoussi/7529fa882ff0b737f257 |
||
14 | if(iframe.contentWindow.location.host !== "") { |
||
15 | // iframe already loaded. |
||
16 | iframe.contentWindow.location.hash = window.location.hash; |
||
17 | } else { |
||
18 | // iframe is just starting. |
||
19 | var newHash = window.location.hash; |
||
20 | var srcStr = iframe.getAttribute('src'); |
||
21 | var words = srcStr.split('#'); |
||
22 | var href = words[0]; |
||
23 | var newSrc = href + newHash; |
||
24 | iframe.setAttribute('src', newSrc); |
||
25 | } |
||
26 | }; |
||
27 | |||
28 | updateIframeHash(); |
||
29 | iframe.contentWindow.addEventListener("message", (event) => { |
||
30 | if (event && event.data && event.data.hash) { |
||
31 | window.location.replace(event.data.hash); |
||
32 | } |
||
33 | }, false); |
||
34 | window.onhashchange = updateIframeHash; |
||
35 | }) (); |
||
36 |