Click here to Skip to main content
14,828,305 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So my website, I'm planning to add music.
But the plan goes well after this thought came up.
If a user clicks on a page on my home page to another part of my site, the music will stop playing I don't want that to happen.
My first thought was to create a txt file or something and when the user leaves that page the current music will be recorded and when that page finishes loading, it will continue on from there.
But how do you modify a txt file with javascript?

What I have tried:

I tried searching up info about modifying txt files but they do not explain them in a way I understand
Posted
Updated 11-Dec-20 3:51am

You can't modify local files from Javascript.

But that's not your question. Your question is how to keep track of the progress of an <audio> element across page loads.
<audio>: The Embed Audio element - HTML: HyperText Markup Language | MDN[^]

The best solution would be to use session storage:
Window.sessionStorage - Web APIs | MDN[^]
   
An option, similar in its idea, to Solution 1 (Richard Deeming) is to use (learn) php. PHP is a server side language. It can do two things that are useful to your problem.

It can edit files (that are also on the server side - not on the client)
It can store data and share it between pages (in what are called SESSION variables).

If you are using javaScript, php is not that much different. The abilities it will add to your web-programming are incalculable in how they'll improve things.

You can learn it, from the ground up and without any pain, here.[^]

Besides the ability to customize pages you send to users, you'll be able to access databases like MySQL, SQL, etc.

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900