This code works in both IE and FF
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<input type="text" id="txt1" />
<input type="button" id="btn1" value="Go" />
<script type="text/javascript">
function changeLocation(e) {
var val = document.getElementById("txt1").value.toLowerCase().replace(/^\s+/, "").replace(/\s+$/, "");
if(val.indexOf("http://")==0) {
window.location.href = val;
return;
}
if(val.indexOf("www.")==0) {
window.location.href = "http://" + val;
return;
}
switch(val) {
case "":
return;
case "google":
window.location.href = "http://www.google.com";
return;
case "yahoo":
window.location.href = "http://www.yahoo.com";
return;
default:
window.location.href = "http://www.csun.edu";
}
}
var btn = document.getElementById("btn1");
btn.addEventListener? btn.addEventListener("click", changeLocation, false): btn.attachEvent("onclick", changeLocation);
</script>
</div>
</body>
</html>
Bookmarks