[Jslib] Re: Detect OS?

Henrik Gemal spam at gemal.dk
Thu Apr 22 09:15:00 EDT 2004

Henrik Gemal wrote:

> Is there a JSLib function available to return the name of the OS?
> Is not it would be a nice feature

Perhaps something like this:

-------------- next part --------------
/*** -*- Mode: Javascript; tab-width: 2;
The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.

The Original Code is jslib team code.	
The Initial Developer of the Original Code is jslib team.

Portions created by jslib team are
Copyright (C) 2000 jslib team.	All
Rights Reserved.
Original Author: Henrik Gemal <mozilla at gemal.dk>

if (typeof(JS_LIB_LOADED)=='boolean') {

const JS_OS_LOADED	 = true;
const JS_OS_FILE		 = 'os.js';

/*********** VALIDATE *******************/

function detectOS () {
	if (navigator.platform.indexOf("Win") == 0)
		return "win32";
	else if (navigator.platform.indexOf("Linux") == 0)
		return "linux";
	else if (navigator.platform.indexOf("Mac OS X") != -1)
		return "macosx";
	else if (navigator.platform.indexOf("Mac") != -1)
		return "macos";
		return null;

function detectSeparator() {
	var os = detectOS();
	if (os)
		if (os == "win32")
			return "\\";
		else if (os == "linux")
			return "/";
		else if (os == "macos")
			return ":";
		else if (os == "macosx")
			return "/";
			return null;
		return null;

/*********** VALIDATE *******************/

jslibDebug('*** load: '+JS_OS_LOADED+' OK');

// If jslib base library is not loaded, dump this error.
		dump("JS_ library not loaded:\n"													 +
				 " \tTo load use: chrome://jslib/content/jslib.js\n"						+
				 " \tThen: include(jslib_os);\n\n");

More information about the Jslib mailing list