Mark Ma
Mark Ma

Reputation: 1362

Keep audio play while refreshing the page

I know we can use AJAX to change page area so the page is not closed (then audio will not stop), but what if I pressed the refresh button? I have Googled a lot but didn't find a solution.

This is possible, because Jamendo has implemented this feature (Even in the refreshing process, the music continues playing).

Upvotes: 3

Views: 1356

Answers (1)

id.ot
id.ot

Reputation: 3141

We can prevent the refresh of the page using the F5 button using Javascript.

if ((e.which || e.keyCode) == 116) e.preventDefault();

[update] The above works great but regarding the browser refresh button and CTRL + R I've just confirmed the following will force a pop-up to the user to confirm they want to leave.

window.onbeforeunload = function () {return false;}

Why not just use AJAX?

Upvotes: 1

Related Questions