JavaScript output for variables to print filename working locally but not on Moodle...

Hello Heroes!

After trials, tribulations, heartbreak and pain I finally worked out the Java code to place variables into file names to save/print the result sides. It worked perfectly and I was extremely proud of myself as I am not a programmer.

All was going well until I uploaded to Moodle and tested it on the server...

Instead of my student names and course name in the file name area, all I could/can get was player.pdf....

Here is my code:

var player = GetPlayer();
var first=player.GetVar("FirstName");
var middle=player.GetVar("MiddleName");
var last=player.GetVar("LastName");
var title=player.GetVar("CourseTitle");
document.title=first + " " + middle + " " + last + " " + "-" + " " + title;
window.print();

All the variables have been checked, like a million times, and it does work brilliantly locally.

Any assistance would be most welcome!

I've added on of the modules below.

79 Replies
MarkAnthony Chesner

Is anyone up for a challenge....

I am trying to have a full-screen action at the beginning of my interaction. I've seen the posts here but they all have a black background which is undesirable.

I found this on the web: https://usefulangle.com/post/12/javascript-going-fullscreen-is-rare#:~:text=Full%2Dscreen%20can%20be%20activated,programmatically%20using%20Javascript%20Fullscreen%20API.

I was wondering if this could be adapted for use in storyline? tHE HTML is in the attached zip file.

If so, I think it would make a lot of heroes happy! 

Or, if you already have a solution to activate F11....?

As always, THANK YOU!!!!

UPDATE: I don't believe it, but I did it! Well, with lots of copy and paste, research and testing!!!

First, I found many working scripts from here and StackOverflow and settled on the following:

function requestFullScreen(element) {
// Supports most browsers and their versions.
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;

if (requestMethod) { // Native full screen.
requestMethod.call(element);
} else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}

var elem = document.body; // Make the body go full screen.
requestFullScreen(elem);

But it still had the black background in fullscreen mode....

Did more research and found out that by changing the "var elem = document.body;" to "var elem = document.documentElement;" it stretches the interaction to fullscreen just like F11...

Here is the final javascript that I have applied to a button:

function add_script(scriptURL,oID) {
var scriptEl = document.createElement("script");
var head=document.getElementsByTagName('head')[0];
scriptEl.type = "text/javascript";
scriptEl.src = scriptURL;
scriptEl.id=oID;
head.appendChild(scriptEl);}

//only want to add these once!
if(document.getElementById('jquery')==null){
add_script("https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js","jquery");
}
function requestFullScreen(element) {
// Supports most browsers and their versions.
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;

if (requestMethod) { // Native full screen.
requestMethod.call(element);
} else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}

var elem = document.documentElement; // Make the body go full screen.
requestFullScreen(elem);

Please share!!!!

Thank you all again so very much for your help!!!!!