Close Non-Custom Results Window - How?

For some testing that I'm implementing, one requirement is that if the student fails the test, he/she can not see the correct answers. (These are regulatory tests, so it is possible to memorize the questions and answers to pass.) On the other hand, if someone does pass, they must be shown the correct answers to any questions they did miss.

This is difficult but possible using the Custom Results, because I can add an action to that page to close itself if the student has a failing score. However, the Test Results page is absurdly buggy and routinely either fails to close for several minutes (!) or freezes the entire course forever on loading.

I could get away with the uncustomized results window (though it is not ideal and is very ugly) but I can't show it to those who fail, and since it is dynamically generated I can't add an Action to it.

I thought of using JavaScript to close it, but of course I don't have access (to the best of my knowledge) to the window handle for the Test Results window. It has the window title "OQ Test" but of course that helps not at all.

I did try the code

However, this did not work, and the alert dialog just reads "The page at says: [object Window].

I know that some Forum participants have delved deep into the Lectora internals. Anyone know of a way to get the handle to the results window, or otherwise to close it via JavaScript (or any other way)? If I could close/hide that window, it would solve my problem.


Discussion (14)

Thinking about it: if it was possible to display a review of missed questions, without using the Lectora "Show test results" option, that would solve the problem. I need an automated way to do this, though, because I'm creating dozens of tests identical in every way except for the questions and I don't want to have to hand-code many hundreds of pages to make it work. Since Actions don't have any way to process arrays and Lectora doesn't have an integral scripting language, that would mean needing access to Lectora functionality in JavaScript, something that appears not to be documented anywhere.

Gah. Now the non-custom results window is displaying with no OK or Print button, rendering it useless. Why?

EDIT: actually, I mean the custom results window when re-enabled it. The text is absurdly huge and the bottom of the page, including the answer to the last question, is cut off.

This is excellent advice ... if I were just starting the project, and if I could design my own tests. Neither is true. I already have dozens of tests with many hundreds of questions. Hand-retooling them all is exactly what I'm trying to avoid.

Similarly, I don't get to pick my own questions (and thus, my own question types). They're supplied by a demi-governmental regulator. I just implement them.

So you are absolutely right, and I would really, really rather not do it that way.

I actually do have it review the test questions page by page. It took awhile to set up the first one I guess, but for new titles I just copy my test and change the questions. Basically I create an action group on each page with the actions to go to a question only if that question was answered incorrectly. Then the next button runs this action group only if the user is reviewing the test. I guess it's complicated to explain and you might want to do it your own way. But as long as you make one that works for you, you can use it as template and not have to reenter all these actions on each title. Although if you want to change the question type, you may have to redo some of the actions. One simple advice if creating such a template is to always select multiple choice as the question type for true/false questions so that you don't have to create a new question if you want to change it to a regular multiple choice question.

This is a really long thread of just me, isn't it? But for the sake of anyone coming along later: Trivantis support tells me that the custom results problem is a known bug in version 16. My contact hopes it will be fixed in Service Pack 1 ... eventually.

so the code does the following:

setInterval( "undefined", 100 ); //this executes the code thats in quotes every 100 milliseconds. this is done to resolve timing issues because it takes a bit of time to open the results page.

the code thats in the quotes is:

if( resWind undefined resWind.finishTestResults ) resWind.finishTestResults()

this basically says if there is a resWind variable AND there is a resWind.FinishTestResults function, call the function. the calling the function bit is accomplished by resWind.finishTestResults()

technically you can just call resWind.finishTestResults() directly, but you would need to put a delay of a half second or more on the action so you give the browser enough time to load the results page. you can try that to see if it works.

which version of lectora are you working with?

If I use the Google Chrome JavaScript debugger, the page that won't display says:

Uncaught SyntaxError: Unexpected token if

a001_oq_test_end_of_test.html:724 Uncaught ReferenceError: findWH is not defined(anonymous function) @ a001_oq_test_end_of_test.html:724

a001_oq_test_end_of_test.html:734 Uncaught ReferenceError: button9422 is not defined(anonymous function) @ a001_oq_test_end_of_test.html:734

a001_oq_test_end_of_test.html:760 Uncaught ReferenceError: image2853 is not defined(anonymous function) @ a001_oq_test_end_of_test.html:760

a001_oq_test_end_of_test.html:779 Uncaught ReferenceError: image28298 is not defined(anonymous function) @ a001_oq_test_end_of_test.html:779

a001_oq_test_end_of_test.html:787 Uncaught TypeError: text28301.addHeading is not a function

So it would appear that there's some sort of problem with this JS, and it's interfering with the JS already on that page. I wonder if I can make this a function for the entire course and then call it from the page?

You can try closing a non-custom test results window with following action

create an action to "Run JavaScript"

enter the following as javascript:


executing that action while a non custom results window is up will close the window and move you to the next appropriate page whether you have passed or failed.all you have to do is put the appropriate condition to execute the action. for instance, put that action as the second action of the Done button for the test and put a condition on it that checks whether the test is passed or failed.

hope that helps, i did very minimal testing with it so it may have some holes.

That sounds like exactly what I needed.

However, when I put that script anywhere on the last page of a test--whether it is triggered by a mouse click or an OnShow action--the page won't display correctly. All inherited controls (like progress indicators and navigation buttons) as well as all added elements like buttons and images are not shown, except the text blocks, which are the only things that do show, but in in small, unformatted text. I even deleted and recreated the page, and this happens reliably and repeatably. I've confirmed this in both AICC and SCORM publishing.

If I change the code to a Hello, World snippet (window.alert("undefined) the page displays normally. This is really odd.

I can't parse your code. (I have very, very limited knowledge of JavaScript.) Can you perhaps give a short explanation? I'd really appreciate it.

Hmm ... can a syntax error in JS cause Lectora to fail to display a page? Is there one there? As I said, I don't really know much JS.

I found out why you are getting JavaScript errors with me initial action JavaScript. when copying from the code from the browser and pasting into Lectora, the quotes are not correct. after pasting into lectora, delete each quote and manual type it back in. you should be good to go.

Sr. Prieto, you have saved my sanity and possibly this project. Thank you!

I had figured out the quotes were not meant to be there by checking the syntax of the command at W3Schools, but as it turns out putting that code in a script even without the quotation marks made the page refuse to display. As you suggest, I cut out just the actual command to close the results window, and used conditional Actions to repeat it at 0.1, 0.5, and 1 second after the user clicks Submit--that means that even if it opens quite slowly, it will still be closed almost immediately.

It works!

How did you find out about the resWind variable and the resWind.finishTestResults functions? I have been unable to locate any documentation of the Lectora JavaScript, anywhere. Did you just read through all their JS files and figure them out?

There wouldn't happen to be a similar command to close the custom results window, by any chance? That would come in very handy.

Again, thank you. If we're ever in the same place, let me buy you a drink.

Hmm ... the custom results page opens in the main window (the way I have it set up), so I'd need JS to trigger the "process test/survey" action based on variable values. Unfortunately I doubt (haven't tested) that resWind.finishTestResults() will work with the non-custom results window not displayed. I think I'll test that.

Well, again, thanks. You have been a huge help.

I'm glad that worked for you!

I created a clean title with a test and results, then just went through the JavaScript looking for 2 things: When the window is opened, and when the user clicks ok to hide the window. When the window was opened, it stored an object in the variable resWind. inspecting the object, it was a standard html dom object, so i knew at that point that would give me full access to that window, including functions defined there. I then found out when the user clicks ok, a javascript function called finishTestResults is called. I do all of this with the chrome dev tools.

Those functions were never intended for direct usage, so they can't be found in any documentation. In fact those functions could change at any point in time with new releases of Lectora. So technically its not a best practice to do what we just did. But odds are it won't change at all. if it does break in a future release, we find a new way to do it!

custom test result are different. there isn't a resWind for that window, so you would have to use some javascript to find the window.

Discussions have been disabled for this post