For anyone that's too lazy to check which link to click, you have two alternative options. The first is that you can use IE (I feel dirty recommending IE, but it's lax security can be useful) to open
the code below assuming your security settings are not too high. The other option for firefox users is to just save this as an html file and run it locally in your browser. Unfortunately, you can't do cross-domain ajax requests and I haven't figured out how to work around this..
Anyways, all this does is check the city's status and load the right url for what is needed. If someone has a better way to implement this, then I'd be happy to try it out. I did already try to do this in php, but couldn't because my host doesn't allow opening remote files. It's probably for security reasons, so I doubt I could get it changed.
Code: Select all
<html>
<head>
<script type="text/javascript">
var req;
var city = 'http://schlag2b.myminicity.com/';
var target = '';
var ind, tra, sec, env;
var response;
function loadXMLDoc(url)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
alert("Permission UniversalBrowserRead denied.");
}
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}
function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
response = req.responseXML.documentElement;
ind = response.getElementsByTagName('unemployment')[0].firstChild.data;
tra = response.getElementsByTagName('transport')[0].firstChild.data;
sec = response.getElementsByTagName('criminality')[0].firstChild.data;
env = response.getElementsByTagName('pollution')[0].firstChild.data;
if ( response.getElementsByTagName('unemployment')[0].firstChild.data > 0 ) {
target = 'ind';
} else if ( response.getElementsByTagName('transport')[0].firstChild.data < 100 ) {
target = 'tra';
} else if ( response.getElementsByTagName('criminality')[0].firstChild.data > 0 ) {
target = 'sec';
} else if ( response.getElementsByTagName('pollution')[0].firstChild.data > 0 ) {
target = 'env';
}
window.location = city + target;
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
loadXMLDoc(city + 'xml');
</script>
</head>
<body>
</body>
</html>