diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index 4744281c..8ebdef08 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -74,9 +74,13 @@ export default class Root extends Component { }); } - checkUrlHash() { - if (window.location.hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) { - const comment = document.querySelector(window.location.hash); + checkUrlHash(e) { + const hash = e ? `#${e.newURL.split('#')[1]}` : window.location.hash; + + if (hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) { + if (e) e.preventDefault(); + + const comment = document.querySelector(hash); if (comment) { setTimeout(() => { diff --git a/web/app/embed.js b/web/app/embed.js index 43cf3428..d9d7c856 100644 --- a/web/app/embed.js +++ b/web/app/embed.js @@ -75,11 +75,12 @@ function init() { } function postHashToIframe(e) { - if (!e && location.hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) { - iframe.contentWindow.postMessage(JSON.stringify({ hash: location.hash }), '*'); - } else if (e && e.newURL.includes(`#${COMMENT_NODE_CLASSNAME_PREFIX}`)) { - e.preventDefault(); - iframe.contentWindow.postMessage(JSON.stringify({ hash: `#${e.newURL.split('#')[1]}` }), '*'); + const hash = e ? `#${e.newURL.split('#')[1]}` : window.location.hash; + + if (hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) { + if (e) e.preventDefault(); + + iframe.contentWindow.postMessage(JSON.stringify({ hash }), '*'); } } }