Skip to content

Commit

Permalink
Set title attr from title element
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjbradshaw committed May 24, 2024
1 parent 815d80c commit 96befec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/child/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions packages/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
}

Expand Down Expand Up @@ -480,6 +480,12 @@ See <u>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
}
Expand Down Expand Up @@ -538,14 +544,18 @@ See <u>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

case 'init':
resizeIFrame()
checkSameDomain(iframeId)
checkVersion(messageData.version)
checkVersion(messageData.msg)
started()
on('onReady', messageData.iframe)
break
Expand Down

0 comments on commit 96befec

Please sign in to comment.