If I create a publication and post it to 2 different websites ( domain.xyz and home.tld) is there a way either using javascript or other methods in SL2 for a slide in the publication to know its host/published location e.g could I have a text entry update with "Welcome to %domain" and depending on which site I visited I would get "Welcome to domain.xyz" or "Welcome to home.tld" but I wouldn't have to create 2 versions of the same publication and hard code values
var firstDot = window.location.hostname.indexOf('.'); var tld = ".net"; var isSubdomain = firstDot < window.location.hostname.indexOf(tld); var domain;
if (isSubdomain == true) { domain = window.location.hostname.substring(firstDot == -1 ? 0 : firstDot + 1); } else { domain = window.location.hostname; } var player = GetPlayer(); player.SetVar("domain",domain);
Make sure you have created a text variable called domain in Storyline.
Thanks for responding. Your solution is more elegant than I actually need but it did point me to window.location so really appreciate that as javascript is not my strong point
My solution is
var Thisdomain; var ThisPage; Thisdomain = window.location.hostname; ThisPage = window.location.pathname; var player = GetPlayer(); player.SetVar("Domain",Thisdomain); player.SetVar("HostPage",ThisPage);
Which gets you Thisdomain is the domain value e.g. myhost.com ThisPage is the path to the html file created by articulate and used to launch the publication e.g. /folder/story_html5.html or where ever on the host the file is saved
4 Replies
Hi Michael,
Give this a try:
Make sure you have created a text variable called domain in Storyline.
Hi Matthew,
Thanks for responding. Your solution is more elegant than I actually need but it did point me to window.location so really appreciate that as javascript is not my strong point
My solution is
var Thisdomain;
var ThisPage;
Thisdomain = window.location.hostname;
ThisPage = window.location.pathname;
var player = GetPlayer();
player.SetVar("Domain",Thisdomain);
player.SetVar("HostPage",ThisPage);
Which gets you
Thisdomain is the domain value e.g. myhost.com
ThisPage is the path to the html file created by articulate and used to launch the publication e.g. /folder/story_html5.html or where ever on the host the file is saved
Glad you got it figured out!
Thanks for stopping back in to share, Michael, as it may help others in the future! :)