473,508 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript implement weather forecast can't run in Firefox

1.Ajax.
2.http://j.maxmind.com/app/geoip.js for get client city.
3.Google weather API.

IE test is passed!But others browser can't,why?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  3. <HTML>
  4.  <HEAD>
  5.   <TITLE>IP_Weather</TITLE>
  6.   <script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
  7.   <SCRIPT type="text/javascript">
  8.     var weather={"onReady":false};
  9.  
  10.     function IpWeather()
  11.     {
  12.         var xmlhttp=false;
  13.        /* Create a new XMLHttpRequest object to talk to the Web server */
  14.  
  15.         /*@cc_on @*/
  16.         /*@if (@_jscript_version >= 5)
  17.         try
  18.         {
  19.              xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  20.         }
  21.         catch (e)
  22.         {
  23.             try 
  24.             {
  25.                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  26.             } 
  27.             catch (e2) 
  28.             {
  29.                 xmlhttp = false;
  30.             }
  31.         }
  32.         @end @*/
  33.         if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
  34.         {
  35.             xmlhttp = new XMLHttpRequest();
  36.         }
  37.  
  38.         xmlhttp.open('GET', 'http://www.google.com/ig/api?weather='+geoip_city(), true);
  39.         xmlhttp.send("");
  40.  
  41.         xmlhttp.onreadystatechange = function()
  42.         {
  43.             if (xmlhttp.readyState == 4)
  44.             {
  45.               var weatherXML = xmlhttp.responseXML;
  46.               
  47.                 var now = weatherXML.getElementsByTagName("current_conditions")[0];
  48.                 var now_t = now.getElementsByTagName('temp_c')[0].getAttribute('data');
  49.                 var now_w = now.getElementsByTagName('wind_condition')[0].getAttribute('data');
  50.                 var now_c = now.getElementsByTagName('condition')[0].getAttribute('data');
  51.                 var now_h = now.getElementsByTagName('humidity')[0].getAttribute('data');
  52.  
  53.                 var today = weatherXML.getElementsByTagName("forecast_conditions")[0];
  54.                 var t_max = today.getElementsByTagName('high')[0].getAttribute('data');
  55.                 var t_min = today.getElementsByTagName('low')[0].getAttribute('data');
  56.  
  57.                 //put weather information in JSON,change onReady=True
  58.                 weather={"t_now":now_t,"wind":now_w,"cloud":now_c,"humidity":now_h,"t_max":t_max,"t_min":t_min,"onReady":true};    
  59.             }
  60.         }    
  61.     }
  62.  
  63.     IpWeather();
  64.  
  65. </SCRIPT>
  66. </HEAD>
  67.  
  68. <BODY>
  69. <div id='target'></div>        
  70. </BODY>
  71.  
  72. <script type="text/javascript">
  73.         function weatherInfo()
  74.         {
  75.             if(weather.onReady)
  76.             {
  77.                 document.getElementById('target').innerHTML="Weather:"+weather.cloud+" Temperature now:"+weather.t_now+"℃ whole day between:"+weather.t_min+"--"+weather.t_max+"℃  "+weather.humidity+" "+weather.wind;
  78.             }
  79.             else
  80.             {
  81.                 document.getElementById('target').innerHTML="loading....";
  82.                 setTimeout("weatherInfo()",100);
  83.             }
  84.         }
  85.         weatherInfo();
  86. </script>
  87. </HTML>
  88.  
  89.  
  90.  
Oct 11 '10 #1
1 2511
gits
5,390 Recognized Expert Moderator Expert
do you get an JavaScript error in Firefox's or Chrome's error consoles?
Oct 11 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
19507
by: Amir | last post by:
I have a common Jscript function in my "common.js" file It is: function submitForm(frm,action){ frm.action=action; frm.submit(); return(false) }
2
1311
by: Amir | last post by:
I used FireFox Jscript debuging capabilities but it says: frm variable doesn't have the property Action function submitForm(frm,action){ frm.action=action; frm.submit(); return(false) }...
4
2739
by: cjl | last post by:
Hey all: I am preloading a large number of images for my web application, and I want to display something indicating progress. So I am simply swapping the visibility of an animated gif (which...
4
7720
by: David McNerney | last post by:
Would anyone be able to tell me why I get an error in FireFox 1.5.0.1 for MacOSX when I type some text and hit Enter in the following form: <html> <body> <form action="http://example.com"...
3
2614
by: coolguyraj | last post by:
Hi, I have a javascript function that does a calculation and displays the result in the third function.The function is triggered by onblur function.It does not seem to work in IE nor Firefox. ...
15
1615
by: qwarehouse | last post by:
Hello, I am having an issue with javascript in firefox. On this URL, there should be a menu displayed above a dashed line. Works ok in IE6 & 7 but no menu displays in firefox. Any sugestions? ...
4
4313
by: simikc | last post by:
Hi, I am using a javascript function for hiding a particular html row while clicking the check box. Each row corresponds to different checkbox. The code I have used is: <asp:Checkbox...
3
1613
by: skwebmedia | last post by:
<script language="javascript" type="text/javascript" > function showflash(i) { if (i==1) window.parent.document.getElementById('V1').movie = "flash/Live-Media-sks.swf"; else if (i==2)...
2
11135
by: ejrfigueiredo | last post by:
Hi, Is there a way to get a script function to save a page without the execCommand (which works on IE but doesn't on Firefox). Below there's the code I'm using, I took it from a template page...
2
2767
by: ozalkl | last post by:
hi everyone, this is my 1st post here in this community forum, just would like to say "HI" to everyone. i would like to share with you my experience in developing multiple dependency selection...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.