Reload Page using Javascript
Copy link to clipboard
Copied
I developed a Captivate 8.01 project and I'm using Moodle as LMS.
I need to "Reload" the main web browser page when I Exit the project, so I tried using this JavaScript code: "location.reload(true);" but is not working.
Should I use the Captivate Common JS interface to run this code, and if true, how do I do that (how do I implement it)? Thank you.
Copy link to clipboard
Copied
What do you mean by the main web browser page?
Are you trying to get back to the course menu?
Where are you executing that code?
Copy link to clipboard
Copied
Thanks for your reply.
My project is divided in two parts: Course and Exam (two separate project/SCORM files). My LMS shows two links (Course/Exam) in the course page, but the Exam link is not active until student finishes the course. Both, the Course and the Exam open in a separate browser window after clicking the link(s).
I set my Course project end options to "Close Project", so in the last slide of the course, a button "Exits" the course, and the course window closes.
The issue is, when student finishes the Course and exits, the LMS shows the original page with the Course/Exam links, but the Exam link will not be active until student Reloads the browser page. Then the browser page updates, and the Exam link is active (student can go to the exam.) So basically, I'm just trying to automatically reload the main page so the student doesn't have to.
I tried putting the code on an Advanced Action assigned to the Exit button of the last slide (with both, Exit and Reload code); also tried placing the code in the last-slide's On-Exit action, but it doesn't work. Browser page just doesn't reloads.
Copy link to clipboard
Copied
We have the same type of issue sometimes just showing completion.
You could try executing some script attached to the body tag in the html page holding each Course.
<body onUnload="window.opener.location.reload();"
or
<body onUnload="window.opener.location.href = window.opener.location.href;"
Copy link to clipboard
Copied
Since the course page is generated by Moodle, I'm not sure we can do that, will check.
My main issue was that maybe the way I'm setting the code is incorrect, because Captivate requires the use of the Common JS Interface for proper JavaScript operation. Don't understand how to set the code this way.
I can always ask students to press "F5" to reload, and the problem is fixed. Thanks for your help.
Copy link to clipboard
Copied
I meant in the html page (index.htm) that Captivate generates.
I use my own SCORM functions, and this is set for courses running in a frame, but this is our exit code:
function exitCourse()
{
var api = getAPIHandle();
var result = "false";
if (api != null)
{
api.LMSSetValue("cmi.core.exit", "suspend");
api.LMSFinish("");
window.top.location="/learn6.asp?sessionid="+(getUrlVars()['sessionid'])+"&rootclass="+(getUrlVars()['rootclass'])+"&classid="+(getUrlVars()['classid'])+"&c=&courseid=0&mode=";
}
else
{
var win = window.open("","_top","","true");
win.opener = true;
win.close();
}
}
function getUrlVars()
{
var vars = [], hash;
var hashes = window.top.location.href.slice(window.top.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++)
{
hash = hashes.split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
Copy link to clipboard
Copied
I tried both but it didn't work. Wondering if changes to the Captivate html file are correct.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Copyright [2012] Adobe Systems Incorporated. All rights reserved -->
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="captivate.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FRA 218 - Engineering</title>
<!-- Include external JS files -->
<script language="JavaScript1.2" src="standard.js" ></script>
<script language="JavaScript1.2" src="scormdriver.js" ></script>
<script language="JavaScript1.2" src="SCORM_utilities.js" ></script>
<script language="JavaScript1.2" src="Utilities.js" ></script>
<script language="JavaScript1.2">
//Register event handlers
window.onkeypress = CheckForDebugCommand;
window.onload = OnloadActivities;
window.onbeforeunload = DoFinish;
window.onunload = DoFinish;
blnDebug = false ;
</script>
</head>
<body bgcolor="#f5f4f1" onUnload="window.opener.location.reload();">
OR
<body bgcolor="#f5f4f1" onUnload="window.opener.location.href = window.opener.location.href;">
<div id = "CaptivateContent">
<noscript>
This course requires JavaScript to be enabled in your browser.
Please enable JavaScript, then relaunch the course.
</noscript>
</div>
</body>
</html>
Copy link to clipboard
Copied
I'll try and test it in the SCORM Cloud since it opens in a new window and see what I can come up with. Probably sometime this weekend.

