Welcome to WebmasterWorld Guest from 54.162.12.134

Forum Moderators: open

Message Too Old, No Replies

Set parameters of iframe using Java Script

     
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&amp;date_fcast=20120118_03&amp;lat=-23.95628&amp;lon=150.266667&amp;units=ft&amp;windunits=kph&amp;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
2:33 pm on Jan 18, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month




<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) +
"&amp;date_fcast=" +
yyyy +
(mm < 10? "0" + mm: mm) +
(dd < 10? "0" + dd: dd) +
"_03&amp;lat=-23.95628&amp;lon=150.266667&amp;units=ft&amp;windunits=kph&amp;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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month