feat(engine): ⚡️ Redirect on current window when embedded
This commit is contained in:
@ -126,10 +126,27 @@ const executeRedirect = (
|
|||||||
{ typebot: { variables } }: LogicContext
|
{ typebot: { variables } }: LogicContext
|
||||||
): EdgeId | undefined => {
|
): EdgeId | undefined => {
|
||||||
if (!step.options?.url) return step.outgoingEdgeId
|
if (!step.options?.url) return step.outgoingEdgeId
|
||||||
const tempLink = document.createElement('a')
|
const formattedUrl = sanitizeUrl(parseVariables(variables)(step.options.url))
|
||||||
tempLink.href = sanitizeUrl(parseVariables(variables)(step.options?.url))
|
const isEmbedded = window.parent && window.location !== window.top?.location
|
||||||
tempLink.setAttribute('target', step.options.isNewTab ? '_blank' : '_self')
|
if (isEmbedded) {
|
||||||
tempLink.click()
|
if (step.options.isNewTab)
|
||||||
|
return ((window.top as Window).location.href = formattedUrl)
|
||||||
|
|
||||||
|
try {
|
||||||
|
window.open(formattedUrl)
|
||||||
|
} catch (err) {
|
||||||
|
//Can't access to parent window
|
||||||
|
window.top?.postMessage(
|
||||||
|
{
|
||||||
|
from: 'typebot',
|
||||||
|
redirectUrl: formattedUrl,
|
||||||
|
},
|
||||||
|
'*'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
window.open(formattedUrl, step.options.isNewTab ? '_blank' : '_self')
|
||||||
|
}
|
||||||
return step.outgoingEdgeId
|
return step.outgoingEdgeId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user