diff --git a/web/app/embed.js b/web/app/embed.js index 6c61f401..9c5c2fb2 100644 --- a/web/app/embed.js +++ b/web/app/embed.js @@ -58,6 +58,12 @@ function init() { document.addEventListener('click', postClickOutsideToIframe); setTimeout(postHashToIframe, 1000); + postTitleToIframe(document.title); + new MutationObserver(mutations => postTitleToIframe(mutations[0].target.textContent)).observe( + document.querySelector('title'), + { subtree: true, characterData: true, childList: true } + ); + const remarkRootId = 'remark-km423lmfdslkm34'; const userInfo = { node: null, @@ -242,6 +248,10 @@ function init() { } } + function postTitleToIframe(title) { + iframe.contentWindow.postMessage(JSON.stringify({ title }), '*'); + } + function postClickOutsideToIframe(e) { if (!iframe.contains(e.target)) { iframe.contentWindow.postMessage(JSON.stringify({ clickOutside: true }), '*'); diff --git a/web/iframe.html b/web/iframe.html index 93bcf61e..5e6f7580 100644 --- a/web/iframe.html +++ b/web/iframe.html @@ -104,6 +104,10 @@ if (isItHash) { location.replace(data.hash); } + + if (data.title) { + document.title = data.title; + } } catch (e) {} }