I have the following in "home.html":
<html>
<head>
<script type="text/javascript" src="sandbox.js"></script>
</head>
<body onload="compatibilityCheck();">
<div id="content">
<p>You need to enable JavaScript to use this site</p>
</div>
.....
where "sandbox.js" is:
function compatibilityCheck() {
var compatibilityCheck = new compatibilityCheck;
compatibilityCheck.browser;
compatibilityCheck.cookies;
}
var compatibilityCheck {
browser : function() {
switch(navigator.appName) {
case 'Microsoft Internet Explorer':
if (!navigator.appVersion >= 7) {
document.getElementById("content").innerHTML = "<p>You need IE 7 or 8 to use this site</p>";
};
break;
case 'Firefox':
case 'Chrome':
case 'Safari':
case 'Opera':
return(document.getElementById("content").innerHTML = "<p>You are using"+navigator.appName"</p>");
break;
default:
return(document.getElementById("content").innerHTML = "<p>Please use IE 7, Firefox, Chrome, Safari or Opera</p>");
}
},
cookies : function() {
var tempCookie = new Date();
checkCookie = (tempCookie.getTime() + '');
document.cookie = "checkCookie=" + checkCookie + "; path=/";
if (document.cookie.indexOf(checkCookie,0) < 0) {
return(document.getElementById('content').innerHTML = "<p>You need to enable Cookies to use this site</p>");
}
}
}
Now I am using Opera 10 and when I loaded "home.html" (it is stored on http://localhost.localdomain) I expected it to change "content" to "You are usingOpera"...but it didn't :(. (I have JS and Cookies enabled)
This is my first attempt at OO JS/JSON and would really appreciate it if a more experience programmer could point out where I've gone wrong. Thanks in advance for any help/tips/pointers :)