diff --git a/example/html/index.html b/example/html/index.html index c26b1788c..02b84e9a0 100644 --- a/example/html/index.html +++ b/example/html/index.html @@ -32,6 +32,7 @@

Automagically resizing iFrame

src="../child/frame.content.html" width="100%" scrolling="no" + title="iframe-resizer content examples" >

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..0ae8c646f 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]?.syncTitle) 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 @@ -1035,6 +1045,11 @@ The sizeWidth, sizeHeight and autoResize options have been rep settings[iframeId].postMessageTarget = iframe.contentWindow } + function chkTitle(iframeId) { + const { title } = document.getElementById(iframeId) + return title === '' + } + function processOptions(options) { settings[iframeId] = { iframe, @@ -1043,6 +1058,7 @@ The sizeWidth, sizeHeight and autoResize options have been rep ...defaults, ...checkOptions(options), mode: setMode(options), + syncTitle: chkTitle(iframeId), } setDirection()