pass page title to the iframe

This commit is contained in:
igoradamenko
2019-01-06 20:55:40 +02:00
parent d8c20da881
commit 52578221a9
2 changed files with 14 additions and 0 deletions
+10
View File
@@ -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 }), '*');
+4
View File
@@ -104,6 +104,10 @@
if (isItHash) {
location.replace(data.hash);
}
if (data.title) {
document.title = data.title;
}
} catch (e) {}
}
</script>