homepage Welcome to WebmasterWorld Guest from 54.235.29.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
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&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

 

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) +
"&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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved