Every day, you download a txt file that contains the url and then I have to manually update the index.html file of a pulldown menu. Is there a way to automatically update the url without having to edit the index file? This is an example of how and dialed the file.txt that drain each day and that below a portion of the index file code.
Text1, Text2, and Text3 to remain unchanged, while the url change daily
File_url.txt
<a href='http://example.com/update1/day1.txt'>text1</a><br/>
<a href='http://example.com/update2/day1.txt'>text2</a><br/>
<a href='http://example.com/update3/day1.txt'>text3</a><br/>
in the index file, the url are inserted so
File index.html
<!DOCTYPE html PUBLIC>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>CSS DropDown Menu</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/simple.css" media="screen" />
</head>
<body>
<div id="drop-menu">
<ul id="menu">
<li><a href="http://example.com/home.php"target="principale" >Home</a></li>
<ul>
</ul>
</li>
<li><a href="#"target="principale" >Extra</a>
<ul>
<li><a href='http://example.com/update1/day1.txt'target="principale">text1</a><br/></li>
<li><a href='http://example.com/update2/day1.txt'target="principale">text2</a><br/></li>
<li><a href='http://example.com/update3/day1.txt'target="principale">text3</a><br/></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<iframe name="principale" src="http://example.com/home.php" marginheight="50" height="800" width="100%" allowfullscreen = "true" ></iframe>
</body>
</html>
For example, the next day I can find
File_url.txt
<a href='http://example.com/update1/day2.txt'>text1</a><br/>
<a href='http://example.com/update2/day2.txt'>text2</a><br/>
<a href='http://example.com/update3/day2.txt'>text3</a><br/>
Is there a way to automatically update the reference Url perhaps using Text1, Text2, and Text3 that never change?
If you use server side script like PHP for example, you can use function like readfile()
function to read the entire file then use foreach
function to iterate over it's rows and render the items to your html.
But, if you don't use server side script at once, I think you can expose the txt file so it can be accessed via URL, for example localhost/file_url.txt
then use javascript ajax function to get it's content from URL and render them into your HTML.
Here's the code using javascript to get the content of you file:
<!DOCTYPE html PUBLIC>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>CSS DropDown Menu</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/simple.css" media="screen" />
</head>
<body>
<div id="drop-menu">
<ul id="menu">
<li><a href="http://example.com/home.php"target="principale" >Home</a></li>
<li><a href="#"target="principale" >Extra</a></li>
<ul>
<ul id="dynamic-menu">
</ul>
</div>
<iframe name="principale" src="http://example.com/home.php" marginheight="50" height="800" width="100%" allowfullscreen = "true" ></iframe>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var menuRequest = $.ajax({
url: 'http://localhost:30001/file_url.txt'
});
menuRequest.done(function(data, status, xhr) {
var dynamicMenuWrapper = $('#dynamic-menu');
dynamicMenuWrapper.html(data);
});
});
</script>
</body>
</html>
*note: remember to make your txt file accessible by pointing it to a specific URL
There are a couple of ways to solve this, One is to itterate over the file_url.txt in index.html( index.php? ) You could follow this example in the How to read a file line by line in php
Keep in mind 'file_url.txt' would be the path to where the file is located. Chances are if your structure is like this.
root dir
You would want "./file_url.txt"
...
<li><a href="#"target="principale" >Extra</a>
<ul>
<?php if ($file = fopen("./file_url.txt", "r")) {
while(!feof($file)) {
$line = fgets($file);
# do same stuff with the $line
echo sprintf(
'<li>%s</li>',
$line
);
}
fclose($file);
} ?>
</ul>
</li>
<li><a href="#">About</a></li>
...
Otherwise, I believe javascript ( jQuery ) would have to be the way to go.