-1

The problem is: I have a 'dynamic' link that I load from an iframe. Here's the code(dynamic because i want to load the link with today's date):

<div id="dropdown5" class="tab-pane fade">
  <h3>SOMETHING</h3>
  <iframe id="orariMilano"src="http://www.trenord.it/it/orari/consulta-orario-ferroviario.aspx?__EVENTTARGET=&__EVENTARGUMENT=&__LASTFOCUS=&ctl00%24ctl00%24ctl00%24ContentPlaceHolderDefault%24cp_content%24ctl01%24ucMotoreRisultati_6%24RadioButtonListAndataRitorno=A&ctl00%24ctl00%24ctl00%24ContentPlaceHolderDefault%24cp_content%24ctl01%24ucMotoreRisultati_6%24txtData=**HERE**&ctl00%24ctl00%24ctl00%24......."></iframe>
</div>

Where 'HERE' is the place where i want to put today's formatted date,like "dd/MM/yyyy"

- So my question is,can I get today's date and format that into "dd/MM/yyyy" format and pass it to the link from a JS or jQuery possibly?

Thank you in advance

KarelG
  • 5,176
  • 4
  • 33
  • 49
Asjon
  • 166
  • 2
  • 12
  • 2
    I'm guessing `trenord.it` is not your site, and that the iFrame has cross-origin content, and if so, *no*, you can't do that. – adeneo Jan 18 '16 at 14:20
  • It's not, but i don't want to insert something on the site,i just want to replace 'HERE' with today's formatted date. – Asjon Jan 18 '16 at 14:23
  • Oh, okay, it's rather hard to spot that "HERE" in the really long URL, but **that** you can do, it's just a matter of adding to the URL. – adeneo Jan 18 '16 at 14:40

2 Answers2

1

var link = "http://www.trenord.it/it/orari/consulta-orario-ferroviario.aspx?__EVENTTARGET=&__EVENTARGUMENT=&__LASTFOCUS=&ctl00%24ctl00%24ctl00%24ContentPlaceHolderDefault%24cp_content%24ctl01%24ucMotoreRisultati_6%24RadioButtonListAndataRitorno=A&ctl00%24ctl00%24ctl00%24ContentPlaceHolderDefault%24cp_content%24ctl01%24ucMotoreRisultati_6%24txtData=**HERE**&ctl00%24ctl00%24ctl00%24......";

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();

if (dd < 10) {
  dd = '0' + dd
}
if (mm < 10) {
  m = '0' + mm
}
var today = dd + '/' + mm + '/' + yyyy;

document.getElementById("orariMilano").src = link.replace("**HERE**", today);
<div id="dropdown5" class="tab-pane fade">
  <h3>SOMETHING</h3>
  <iframe id="orariMilano" src=""></iframe>
</div>
arc
  • 4,553
  • 5
  • 34
  • 43
0

here is article about date formating with JS How to format a JavaScript date. After you do that you can easily adjust the link with pure java script or jquery. Here it is the jquery style.

$("a").attr("href", "http://www.google.com/")

where you can use id instead of "a".

Community
  • 1
  • 1