Forum Discussion
Global scope for Javascript variables in Storyline
Hello Guys,
My personal solution is to use a webObject on the first scene, with sessionStorage.
I do load a webObject (first slide and off stage). the code in the index.html is simply :
*************************************
<script>
sessionStorage.setItem("msg_EN","Hello world!");
sessionStorage.setItem("msg_FR","Bonjour le monde!");
sessionStorage.setItem("msg_ES","Hola mundo!");
</script>
*************************************
These become available for each slides even for other webObjects :
var player = GetPlayer();
player.SetVar("greetings",sessionStorage.getItem("msg_EN"));
If you care about making the variables more "private", you can always use base64 encode/decode, here is the function I use:
****************************************
function encodeB64(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function decodeB64(str) {
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
Nice solution Steve