pass page title to the iframe
This commit is contained in:
@@ -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 }), '*');
|
||||
|
||||
@@ -104,6 +104,10 @@
|
||||
if (isItHash) {
|
||||
location.replace(data.hash);
|
||||
}
|
||||
|
||||
if (data.title) {
|
||||
document.title = data.title;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user