| Set parameters of iframe using Java Script
|
djolsen

msg:4408029 | 7:22 am on Jan 18, 2012 (gmt 0) | I have an iframe in a web page the source of which is defined as follows. <iframe src="http://www.#*$!x.com/cgi-bin/map/3dayxc.cgi?date=20120118&date_fcast=20120118_03&lat=-23.95628&lon=150.266667&units=ft&windunits=kph&offset=10 I want to be able to get the current date using javascript and have the cript change the iframe src parameter so that date= the current date and date_fcast=currentdate_03. I am very new to javascript and tend to create pages by reverse engineering other pages :-) Can someone assist. This is for our no-profit club of aviators. D
|
Fotiman

msg:4408123 | 2:33 pm on Jan 18, 2012 (gmt 0) | <iframe id="mapFrame" src=""> <script> var clientDate = new Date(), yyyy = clientDate.getFullYear(), mm = (clientDate.getMonth() + 1), // getMonth returns 0 - 11 dd = clientDate.getDate(), iframeEl = document.getElementById('mapFrame'); iframeEl.src = "http://www.#*$!x.com/cgi-bin/map/3dayxc.cgi?date=" + yyyy + (mm < 10? "0" + mm: mm) + (dd < 10? "0" + dd: dd) + "&date_fcast=" + yyyy + (mm < 10? "0" + mm: mm) + (dd < 10? "0" + dd: dd) + "_03&lat=-23.95628&lon=150.266667&units=ft&windunits=kph&offset=10"; </script>
|
| Does that work? Note, users with JavaScript disabled will not get the same results. Also, this uses the date at the client (which could be anything), so may not produce accurate results. This is probably better handled with server side code (PHP, ASP, etc.). Welcome to WebmasterWorld.
|
|
|