javascript in Storyline - Can you look at my code?

I know SL, but not js. Friend knows js but not SL.

The below code is set to execute when certain keys are hit, but nothing seems to happen. does anyone know if this code is setup right to work with SL

 

Example 1:

alert(document.getElementsByClassName("TabClassActive"));

alert(document.getElementsByClassName("TabClassActive")[0]);

alert(document.getElementsByTagName("Title")[0]);

document.bgColor = "#0033CC";

 

Example 2:

var player = GetPlayer();

alert(player);

player.SetVar("refundpage",True);

 

example 3:

alert(window.document.getElementsByClassName(“im-page-subtitle”)[0]);

var player = GetPlayer();

alert(player.getVar(“refundpage”));

window.document.bgColor = “#990000”;

 

1 Reply
onEnterFrame (James Kingsley)

Hi Ben,

It is a bit hard to tell from these bits what you want to accomplish. All those alerts firing will most likely fail. I am not sure why you want to alert those. Some of them are DOM/JS Objects and won't automatically convert to a string that you can put in an alert. 

If you are trying to use an alert to help you debug the script then I would suggest you replace them with console.log( MSG ). that will write the info the browser's console (in most browsers you hit F12 to open the console).

Additionally document.bgColor was depreciated a long time ago and I am not sure browsers are still supporting it. Best to use document.body.style.backgroundColor 

Hope that helps,

James