I have written my first javascript block which functions correctly in IE, however nothing executes in FF or chrome. have I missed something. Also is there a way to stop IE from prompting to run it? TIA

Javascript

function getCondition()
{
if (window.XMLHttpRequest)
    {// code for ie7+, firefox, chrome, opera, safari
    xmlhttp=new XMLHttpRequest();
    }
else
    {// code for ie6, ie5
    xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
    }
xmlhttp.open("GET","http://www.google.com/ig/api?weather=invercargill",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
i=0;
var x=xmlDoc.getElementsByTagName("current_conditions");
var c=(x[i].getElementsByTagName("condition")[0].getAttribute("data"));
var t=(x[i].getElementsByTagName("temp_c")[0].getAttribute("data"));
var img=(x[i].getElementsByTagName("icon")[0].getAttribute("data"));
document.getElementById("tempAPI").innerHTML="It's "+c+" and "+t+"&deg";
document.getElementById("tempIMG").innerHTML="<img src='http://www.google.com"+img+"' alt='weather image' />";
}

HTML

<body class="t" onload="getCondition()">
Member Avatar for stbuchok

look into using jQuery, it makes a lot of these cross browser issue "Magically" go away.

Member Avatar for jmichae3

http://en.wikipedia.org/wiki/XMLHttpRequest#Support_in_Internet_Explorer_versions_5.2C_5.5_and_6
has a good articleon how to code this. I have not tried it. it says that only ie5,5.5,6 have a problem using XMLHttpRequest. also gives useful code.
the reason for the activex warning is because you are requesting an activex or ole control. this is a red flag to the IE browser. the user has to change their security settrings to allow all activex controls, but this is an unsafe thing to do. try resetting your IE security to defaults and see what happens, maybe this will fix it. I thought XMLHttpRequest was a microsoft signed control, but I don't know for sure. allowing all signed controls is one of the things you can do IF yo uwant to, but this doesn't change the behavior on the web.

you want your browser on the default settings to simulate bahavior on the web.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.