Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

undefined error

Status
Not open for further replies.

aryajur

Programmer
Jul 2, 2003
45
0
0
US
I have a Javascript file (.js) and when I try to run it by double clicking it I get an error that 'navigator' is undefined. Error Code is 800A1391. The initial lines of code for the file is:


var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf("konqueror")!=-1) agent = "konqueror";
else if (agent.indexOf("safari")!=-1) agent = "safari";
else if (agent.indexOf("opera")!=-1) agent = "opera";
else if (agent.indexOf("firefox")!=-1) agent = "firefox";
else if (agent.indexOf("msie")!=-1) agent = "msie";

window.onerror=handleErr;

How to I run it or debug this?

 
Standalone js is not hosted by any "browser". It is hosted by windows script host. Hence, navigotor object is not defined. You can only run through a browser. If you want to check your "double-click" default browser, you wrap it in a html page, say "anyname.htm".
[tt]
<script>
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf("konqueror")!=-1) agent = "konqueror";
else if (agent.indexOf("safari")!=-1) agent = "safari";
else if (agent.indexOf("opera")!=-1) agent = "opera";
else if (agent.indexOf("firefox")!=-1) agent = "firefox";
else if (agent.indexOf("msie")!=-1) agent = "msie";

window.onerror=handleErr;
//etc etc
</script>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top