Antioch Tech Posted June 25, 2020 Share Posted June 25, 2020 My first time posting. I hope this is the correct forum. I need to create links to daily articles on certain web sites. On some sites, the URL for the article that day contains the date. So the article for today would be www.site.com/June/25. How do I write code to put elements of today's date in the link? Link to comment Share on other sites More sharing options...
Ingolme Posted June 25, 2020 Share Posted June 25, 2020 It is complicated. You should probably install a CMS such as Wordpress which does that for you. If you're running on an Apache server the first step would be to use the mod_rewrite directives to control how the URL works. After that you need a server-side programming language to read the URL and choose which content to display based on the URL. Link to comment Share on other sites More sharing options...
Antioch Tech Posted June 27, 2020 Author Share Posted June 27, 2020 I am creating a web page with links to the sites in question. The web page is a stand alone page, not part of a web server. It is on a network share. Link to comment Share on other sites More sharing options...
JMRKER Posted June 27, 2020 Share Posted June 27, 2020 Do you have some sample code of your HTML to view? Link to comment Share on other sites More sharing options...
Antioch Tech Posted June 30, 2020 Author Share Posted June 30, 2020 OK, here it is. And yes, it is a comics page. https://www.gocomics.com/peanuts/2020/06/30 I need to know how to insert elements of today's date in the URL, so each day when we click on the link, it takes you to today's comic. Link to comment Share on other sites More sharing options...
JMRKER Posted July 1, 2020 Share Posted July 1, 2020 Here's a start. I would recommend making the drop-down a dynamic list for the last 30 (?) days from the current date using the Date() object. <select id='Peanuts'> <option value=""> Select </option> <option value="Choose date"> Choose date </option> <option value="2020/06/30"> 2020/06/30 </option> <option value="2020/06/29"> 2020/06/29 </option> <option value="2020/06/28"> 2020/06/28 </option> <option value="2020/06/27"> 2020/06/27 </option> <option value="2020/06/26"> 2020/06/26 </option> </select> <script> console.clear(); function Cartoon() { document.location.href = `https://www.gocomics.com/peanuts/${document.getElementById('Peanuts').value}`; } function init() { document.getElementById('Peanuts').addEventListener('change', Cartoon ) } init(); </script> Link to comment Share on other sites More sharing options...
Antioch Tech Posted July 2, 2020 Author Share Posted July 2, 2020 Thank you for the attempt, but this does not do what I need. I need the link today to point to today's strip. Tomorrow the link will point to tomorrow's strip. Each day the link would point to the strip for that day. Not a list of dates to choose from, but the strip for today's date. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 2, 2020 Share Posted July 2, 2020 https://www.w3schools.com/code/tryit.asp?filename=GGCEXCMWOCBY Link to comment Share on other sites More sharing options...
dsonesuk Posted July 2, 2020 Share Posted July 2, 2020 https://www.w3schools.com/code/tryit.asp?filename=GGD4IX1JNB5A Link to comment Share on other sites More sharing options...
JMRKER Posted July 3, 2020 Share Posted July 3, 2020 22 hours ago, Antioch Tech said: Thank you for the attempt, but this does not do what I need. I need the link today to point to today's strip. Tomorrow the link will point to tomorrow's strip. Each day the link would point to the strip for that day. Not a list of dates to choose from, but the strip for today's date. How many days are to be included into the past? Would be difficult to point to tomorrow's strip until that day has been posted. Link to comment Share on other sites More sharing options...
JMRKER Posted July 3, 2020 Share Posted July 3, 2020 Try this: <!DOCTYPE html><html lang="en"><head><title> Test Page </title> <meta charset="UTF-8"> <meta name="viewport" content="width-device-width,initial-scale=1.0, user-scalable=yes"/> <!-- link rel="stylesheet" href="common.css" media="screen" --> <style> #Peanuts { font-size: 2em; } </style> </head> <body> <a id="Peanuts" href="" target='_blank'>Todays's Peanut Strip</a> <script> function init() { var tday = new Date(); var link = 'https://www.gocomics.com/peanuts/' + tday.getFullYear()+'/'+(tday.getMonth()+1)+'/'+tday.getDate(); document.getElementById('Peanuts').href = link; } init(); </script> </body> </html> 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted July 3, 2020 Share Posted July 3, 2020 You will have problem with date values less than 10, see first example for fix Link to comment Share on other sites More sharing options...
JMRKER Posted July 3, 2020 Share Posted July 3, 2020 2 hours ago, dsonesuk said: You will have problem with date values less than 10, see first example for fix Which post has the problem? I don't see it with my last suggested code. (Works OK using FF on 2020/7/3) Link to comment Share on other sites More sharing options...
Ingolme Posted July 3, 2020 Share Posted July 3, 2020 It depends on whether the website chose to accept numbers without leading zeroes or not. It seems that GoComics is prepared for both kinds of numbers so it is not a problem in this scenario. Link to comment Share on other sites More sharing options...
Antioch Tech Posted July 5, 2020 Author Share Posted July 5, 2020 JMRKER, that worked. Thank you very much. Link to comment Share on other sites More sharing options...
JMRKER Posted July 5, 2020 Share Posted July 5, 2020 1 hour ago, Antioch Tech said: JMRKER, that worked. Thank you very much. You're most welcome. Happy to help. Good Luck! BTW, welcome to the forums. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 5, 2020 Share Posted July 5, 2020 Your welcome, glad i didn't have to rely changing url each time, just use the url from anchor link, and the second does exactly the same but to multiple different url anchor links wherever they maybe, as i said your welcome. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now