Вопрос

I'm working with Moodle 2.6, but this isn't really a Moodle question. An activity is defined as an URL. That URL is just a custom-built video player. When the video ends, it goes back to the Moodle course page. That all works just fine, but the Moodle page doesn't reflect that this activity has been completed until the page is refreshed/reloaded using F5. Here is the javascript code that I've used to detect the end of the video:

    video1.addEventListener("ended", function() {
       history.back(1);
    });

I've tried using this:

    window.location.reload(history.go(-1));

in place of the history.back(1), thinking that this new line held a lot of promise, but no joy. I've tried other things as well, such as changing 'back' to 'go' (with the negative of the value), but that appears to function the same.

This seems like it should be a simple thing to do, but I'm no expert on this stuff, so I'm stumped. How do I get my browser to go back a page then reload it? I'm mainly using IE on the PC, and Safari on the iPad.

EDIT, Additional idea

When I was researching this, one suggestion was to add a unique ID at the end of the URL, such as using the time. So, in my case, I'd want to pull the URL out of the history buffer for the -1 entry and add something like ?123456 (which changes every time), then call that page. Is something like that a good idea, good coding standards, etc?

Это было полезно?

Решение

The right solution would be setting up the URL you'd like to refer the user to.

If this is not possible for you, and answering your question, you can try redirecting the user to the referrer page using location.href:

location.href = document.referrer;

This will redirect the user to the page they came from, and the browser won't try to restore the previous state of the page.

Другие советы

Maybe try Window.history.back() rather than just history.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top