Forum Discussion
Capturing Text from a Shape or TextBox
- 4 days ago
I am confused by your setup description, but I suspect that you expect the text within a slide shape to be contained in the object's value property. Text in a Storyline object, especially formatted text, is generally embedded into an SVG element, broken down into text groups based on the formatting applied. You could extract the text, but not simply. The text is also represented in a hidden part of the page called the shadow-DOM. If, for example, you had a button with a text label of "Press Me", and the object was defined by
const button_1 = object("6UNtrp5jRD9")you could potentially extract the text value by identifying the corresponding button element in the shadow-DOM, and then accessing the innerText property. For example:
// Use the object ID as identified by Storyline, and append 'acc-' to the beginning to obtain the element's ID in the shadow-DOM. let buttonText = document.getElementById("acc-" + "6UNtrp5jRD9").innerText //This would return the value 'Press Me' to the variable buttonText
I am confused by your setup description, but I suspect that you expect the text within a slide shape to be contained in the object's value property. Text in a Storyline object, especially formatted text, is generally embedded into an SVG element, broken down into text groups based on the formatting applied. You could extract the text, but not simply. The text is also represented in a hidden part of the page called the shadow-DOM. If, for example, you had a button with a text label of "Press Me", and the object was defined by
const button_1 = object("6UNtrp5jRD9")
you could potentially extract the text value by identifying the corresponding button element in the shadow-DOM, and then accessing the innerText property. For example:
// Use the object ID as identified by Storyline, and append 'acc-' to the beginning to obtain the element's ID in the shadow-DOM.
let buttonText = document.getElementById("acc-" + "6UNtrp5jRD9").innerText
//This would return the value 'Press Me' to the variable buttonText
Thank you! I had tried variations with and without acc- but what I hadn't tried was innerText. That was the winner. It now does exactly what I wanted it to do.
- HoneyTurner4 days agoCommunity Member
For anyone trying this out themselves, it did not work if I attached the javascript to "when timeline starts on layer". But it did work "when variable changes" or "when button clicked".
Related Content
- 6 months ago
- 7 months ago
- 7 months ago
- 4 months ago