How can I read url from a txt file and use in html? I have a video source url in .txt file. How can I use this url in the html file? Sometimes I want to edit the video source in the .txt file.
In the /videosrc.txt:
http://www.videoexaple.com/videos/video.mp4
In /index.html file:
<html>
<head>
<title></title>
</head>
<body>
<video id="video">
<source id="videosource" src=" -url from /video.txt- " type='video/mp4'>
</video>
</body>
</html>
I would recommend that you give this a read: https://www.w3schools.com/php/php_file_open.asp See the first example and you can see the output of the file.
This shows you how to access information within a file. Then it is just a matter of putting the data at the correct place.
The simplest is to have a file with the extension .js - for example video.js in the same folder as the html file
It looks like this:
const videoURL = "https://www.videoexaple.com/videos/video.mp4";
then in your HTML have
<script src="video.js"></script>
<script>
window.addEventListener("DOMContentLoaded",function() {
document.getElementById("videosource").src = videoURL;
})
</script>
try this
fetch('file.txt')
.then(response => response.text())
.then(text => { document.getElementById("videosource ").src =text;})