Retrieve TOC completed pages into variable

Hello All

Does anyone have a code sample of a javascript to retrieve completed / incompleted page count into a variable from TOC content without using LMS or scorm?

undefined

Regards

Discussion (9)

Just a quick note I need to count the pages which belongs to chapters as completed

G'day Tamer,

pageStatus = trivPageTracking.GetRangeStatus(pageNumber);

This will return "complete" or "notstarted", the pageNumber would start at 1 and end with the number of pages you have in the title. The number of pages in a give chapter is in the TOC but you need a lot of work to get at it, I suggest that you simple take note of the start and end page numbers of each of the chapters and hard wire these for each title, not the best solution but it will work.

HTH

Regards, Peter

Hi Peter,

I have tried it but no luck. I have used the code as follows and you can see the result in screenshot I attached. What can be the issue I am missing?

var cNum=0;

var status="";

for (i=1; i<11;i++){

pageStatus = trivPageTracking.GetRangeStatus(i);

status+= i + " " + pageStatus + " ";

if (pageStatus=="complete") {

cNum += cNum;

}

}

alert(cNum + " " + status);

2017-02-26_23h36_29.png

G'day Tamer,

Well done on the JavaScript, I made some changes, try the following:

var cNum=0;

var status='';

for (i=1; i<11;i++){

pageStatus = trivPageTracking.GetRangeStatus(i);

status+= i + ' ' + pageStatus + ' ';

if (pageStatus=='complete') {

cNum += cNum;

}

}

alert(cNum + ' ' + status);

You had 3 '=' equals in the "if" line.

If you add a TOC that shows pages visited then the count should be the same as what the TOC displays. You will need to clear your cache as each time you launch the page visited data is stored in your cache.

HTH

Thanks for your suggestion. I just created 10 empty pages and a TOC and run JS as follows :

cNum=0;

cNum2=0;

for (i = 1; i < 11; i++) {

pageStatus="incomplete";

pageStatus = trivPageTracking.GetRangeStatus(i);

if (pageStatus==="complete") {

cNum=cNum+1;

}

}

Varpagecount.set(cNum);

undefined

I'm really sorry, I have cNum += cNum; it should be cNum += 1;

That said, I don't know why your TOC shows that pages completed with the function are not completed in the TOC. I don't know how this is possible as it works perfect for me, sorry about that.

Regards, Peter

Hi Peter

I am also shocked why I am getting these random results. There might be a solution but we two are not enough to solve this I think.

Thanks for your help.

Kind Regards

...disregard

So i just gave the script a try everything looks good with it.

However one thing to notice is that this uses a cookie system to track page visitation and display it correctly. If you are in publish preview mode there is the possibility of the status being cached already, which I ran into when i visited each page it stored the "complete" status for the page so when i went to "test" it again that value was already complete

Doing a full publish and storing it on my local webserver and re checking your script there It worked as intended displaying the first page as in progress and each remaining as not started.

That would explain the random behavior when the script is pretty straight forward. To test it correctly deleting the cookie/clearing your cache between visits is a must to see the correct output.

Discussions have been disabled for this post