I have a slate with a Code sandbox, where we let the user click on a link to move to another place (outside Foundry). We want this link to open in a new tab, however, <a href="https://www.example.com" target="_blank">Visit Example.com</a> and equivalent are blocked from Code Sandbox.
How can I open a url in a new tab from Code Sandbox in Slate ?
You can pass an event from CodeSandbox to Slate, and then use the “redirectToUrl” event in Slate to open the URL of your choice.
See https://www.palantir.com/docs/foundry/slate/concepts-events-and-actions-index/#slateredirecttourl
JS:
type or paste code here document.getElementById("button").onclick = () => {
SlateFunctions.triggerEvent("event1", "test");
}
HTML:
<button id="button">
Click me
</button>
and the event:
You will still have a popup, to confirm that you want to move to this page
Note: you can as well pass the url to open via the variable tied to the event, for example
// When the button is clicked set the text box to the current time
document.getElementById("button").onclick = () => {
SlateFunctions.triggerEvent("event1", "https://palantir.com");
}
In the event:
// Optional line, just to see in the network tab what is passed, easier for debugging
console.log("event triggered", {{slEventValue}})
return {
"url": {{slEventValue}},
"target": "_blank"
};