Assignment - "Back to the course" button

Assignment - "Back to the course" button

by Dominique Bauer -
Number of replies: 2
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Here's my answer to this post ↗.

Hello Sathiraju,

It seems to me that this is possible. You will also need to replace "quizattempt" with "submissionaction".

Here is the code for assignment only:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    if (window.location.href.indexOf("https://theURLofyourMoodleSite/mod/assign/view.php") > -1) {
        $("<div style='text-align:center;'><button class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div><div style='text-align:center;position:relative;top:8px;'>OR</div>").insertBefore($("div.submissionaction"));
    };
})
function backtotheCourse() {
    var x = $("ol.breadcrumb li:eq(-2)  > a").attr("href");
    window.location.replace(x);
}
</script>

Here is the code for both quiz and assignment:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    if (window.location.href.indexOf("https://theURLofyourMoodleSite/mod/quiz/view.php") > -1) {
        if ($(".continuebutton").length) {
            $(".continuebutton").css("display","none");
            $("<div style='text-align:center;'><button class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div>").insertBefore($("div.quizattempt"));
        } else {
            $("<div style='text-align:center;'><button class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div><div style='text-align:center;position:relative;top:8px;'>OR</div>").insertBefore($("div.quizattempt"));
        }
    };
    if (window.location.href.indexOf("https://theURLofyourMoodleSite/mod/assign/view.php") > -1) {
        $("<div style='text-align:center;'><button class='btn btn-secondary' onclick='backtotheCourse()'>Back to the course</button></div><div style='text-align:center;position:relative;top:8px;'>OR</div>").insertBefore($("div.submissionaction"));
    };
})
function backtotheCourse() {
    var x = $("ol.breadcrumb li:eq(-2)  > a").attr("href");
    window.location.replace(x);
}
</script>
Average of ratings: Useful (1)
In reply to Dominique Bauer

Re: Assignment - "Back to the course" button

by Arnould Olivier -

Hello,

thanks for this code... In my case, I think it can be a good solution for my users also.

However, it doesn't work for me. I have follow your instructions (head in additionnal HTML, replacing the url with my site in the code).

The new button is here but I have a 404 error when I click it (The requested URL was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.).

I've tried few solutions but unfortunately, I don't really know how codes work.

Maybe, you can have a solution ?

Thanks in advance and sorry for my english (I'm french, as my site that is a moodle 3.9.2+ with lambda theme).