From ed76d7bbcfffa609ff4423c49faa3d71ec2e6a29 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Fri, 24 May 2024 17:29:18 +0100 Subject: [PATCH] #1255 Set iframe title attr from page title in the iframe --- packages/child/index.js | 7 +++++++ packages/core/index.js | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/child/index.js b/packages/child/index.js index 225f221d0..cfbe91f89 100644 --- a/packages/child/index.js +++ b/packages/child/index.js @@ -167,10 +167,17 @@ function init() { startEventListeners() inPageLinks = setupInPageLinks() sendSize('init', 'Init message from host page', undefined, undefined, VERSION) + sendTitle() onReady() isInit = false } +function sendTitle() { + if (document.title && document.title !== '') { + sendMsg(0, 0, 'title', document.title) + } +} + function checkVersion() { if (!version || version === '' || version === 'false') { advise( diff --git a/packages/core/index.js b/packages/core/index.js index f0acdc612..54565e4cb 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -70,7 +70,7 @@ function iframeListener(event) { height: height + getPaddingEnds(compStyle) + getBorderEnds(compStyle), width: Number(data[2]), type: data[3], - version: data[4], + msg: data[4], } } @@ -480,6 +480,12 @@ See https://iframe-resizer.com/setup/#child-page-setup for more details. log(iframeId, `Version mismatch (Child: ${version} !== Parent: ${VERSION})`) } + function setTitle(title, iframeId) { + if (!settings[iframeId]) return + settings[iframeId].iframe.title = title + log(iframeId, `Set title attribute to: ${title}`) + } + function started() { setup = true } @@ -538,6 +544,10 @@ See https://iframe-resizer.com/setup/#child-page-setup for more details. findTarget(getMsgBody(9)) break + case 'title': + setTitle(messageData.msg, iframeId) + break + case 'reset': resetIFrame(messageData) break @@ -545,7 +555,7 @@ See https://iframe-resizer.com/setup/#child-page-setup for more details. case 'init': resizeIFrame() checkSameDomain(iframeId) - checkVersion(messageData.version) + checkVersion(messageData.msg) started() on('onReady', messageData.iframe) break