Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 798
Mark Ma Avatar asked Dec 06 '25 16:12

Mark Ma


1 Answers

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?

like image 133
id.ot Avatar answered Dec 08 '25 05:12

id.ot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!