Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Set parameters of iframe using Java Script

7:22 am on Jan 18, 2012 (gmt 0)

New User

5+ Year Member

joined:Jan 18, 2012
votes: 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.

2:33 pm on Jan 18, 2012 (gmt 0)

Senior Member from US 

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

joined:Oct 17, 2005
posts: 4993
votes: 14

<iframe id="mapFrame" src="">
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) +

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.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members