Looking to append yesterdays date to a URL in a meta html redirect. The goal would be something that works like this.
<meta http-equiv="Refresh" content="5; url=https://cse.google.com/cse?cx=xxx&q="news" after:%yesterdaydate%"/>
Would this be possible with Javascript or HTML?
CodePudding user response:
Quite simply.
After creating a Date, create a date string for yesterday's date.
Set the <meta>
tag - page will redirect to that URL.
NOTE: It would be prudent to do this by creating the <meta>
tag programmatically rather than using innerHTML
, but this will work to demonstrate how it is done.
const date = new Date();
const dateString = new Date(date.setDate(date.getDate()-1)).toLocaleDateString();
const meta = `<meta http-equiv="Refresh" content="5; url=https://cse.google.com/cse?cx=xxx&q=news after:${dateString}"/>`;
document.querySelector('head').innerHTML = meta;