Open a new tab when user clicks on a choice
# 🤝help
c
This is my code in the execute code card. Tried and it didn't work, not sure if anyone knows if it's my code or is it just not possible? const openNewTab = (url) => { const newTab = window.open(url, '_blank') newTab.focus() } openNewTab('https://www.apple.com')
c
You want to open new tab?
c
Yes so imagine clicking on a choice card in the bot, then getting linked directly to Apple's website.
e
There are several ways to achieve the desired behavior: 1. Sending text messages with the links instead of the choices - not as cool but... The user will then click on the desired link and open the website on a new tab if they are talking through the webchat, or in the mobile browser if they are talking through whatsapp or telegram. The conversation can proceed normally or stop. 2. Having the choices that transition to nodes with text messages containing the link (like in the first image) 3. Sending a custom event to your webchat (second image), and then adding the following code to your website:
Copy code
js
window.botpressWebChat.onEvent(event => {
  window.open(event.payload.tabToOpen, '_blank');
}, ['TRIGGER'])
Hope that helps!

https://cdn.discordapp.com/attachments/1137821854682316930/1138689155006726144/image.png

https://cdn.discordapp.com/attachments/1137821854682316930/1138689155270979665/image.png

Hey @wonderful-dusk-90567 this should help you as well!
c
Number 3 is what I was looking for thanks for helping out 🙂 Do you input that code block just below the chatbot embed code or somewhere else?
4 Views