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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am a new user of Javascript. I am

Status
Not open for further replies.

sawsie

IS-IT--Management
Jan 6, 2003
21
0
0
CA
I am a new user of Javascript. I am trying to use the script for browser langauge detection. I would like the browser to detect whether the user is English or French, How can I make the changes in the following script to do that? If you have a suggestions for another script that would be aprecaited too.

//*************** GLOBALS VARS *****************

//******************* BEHAVIOR FUNCTION **********************

// NSJ - 0,1,2: where to go if Netscape 2.0 or above Japanese
// NSnoJ - 0,1,2: where to go it NOT Netscape 2.0 or above Japanese
// IEJ - 0,1,2: where to go if IE 4.0 or above Japanese
// IEnoJ - 0,1,2: where to go if NOT IE 4.0 or above Japanese
// OTHER - 0,1,2: where to go if other browser
// eURL - English URL, often a filename, URL encoded. (ex: file.htm, // jURL - Japanese URL, often a filename, URL encoded. (ex: file.htm,

function checkLanguage(NSJ,NSnoJ,IEJ,IEnoJ,OTHER,eURL,jURL) {
//default to English
var newURL = eURL;
var version = parseFloat(navigator.appVersion);

//first check for Netscape 2.0 or up
if ((navigator.appName.indexOf('Netscape') != -1) && (version >= 2.0)) {

//check for Japanese
if (navigator.appVersion.indexOf('ja') != -1) {

newURL=jURL;
}

//check for IE 4.0 or up
} else if ((navigator.appName.indexOf('Microsoft') != -1) && (version >=4.0)) {

//check for Japanese
if (navigator.browserLanguage.indexOf('ja') != -1) {

newURL=jURL;
}
}
//make it so
if (newURL) {
window.location = unescape(newURL);
document.returnValue = false;
}
}


//******************* API **********************


//Can be used with any tag and any event

function canAcceptBehavior(){
return true;
}



//Returns a Javascript function to be inserted in HTML head with script tags.

function behaviorFunction(){
return "checkLanguage";
}



//Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
//Calls escape to encode URLs. Checks validity of all entries.
//For example, if *any* condition uses URL, the URL field cannot be empty.

function applyBehavior() {
var NSJ, NSnoJ, IEJ, IEnoJ;
var eURL, jURL, OTHER;

with (document.theForm) { // read all values from form
NSJ = NSJp.selectedIndex;
NSnoJ = NSnoJp.selectedIndex;
IEJ = IEJp.selectedIndex;
IEnoJ = IEnoJp.selectedIndex;
OTHER = OTHERS.selectedIndex;
eURL = escape(engURL.value); //URL encode
jURL = escape(jpnURL.value); //URL encode
}

//Check for valid numbers, and URLs exist if required
if ((eURL==&quot;&quot;) && (NSJ==1 || NSnoJ==1 || IEJ==1 || IEnoJ==1 || OTHER==1))
return MSG_NoEURL;
if ((jURL==&quot;&quot;) && (NSJ==2 || NSnoJ==2 || IEJ==2 || IEnoJ==2 || OTHER==2))
return MSG_NoJURL;


return &quot;checkLanguage(&quot;+NSJ+&quot;,&quot;+NSnoJ+&quot;,&quot;+IEJ+&quot;,&quot;+IEnoJ+&quot;,&quot;+OTHER+&quot;,'&quot;+eURL+&quot;','&quot;+jURL+&quot;')&quot;;
}



//Returns a dummy function call to inform Dreamweaver the type of certain behavior
//call arguments. This information is used by DW to fixup behavior args when the
//document is moved or changed.
//
//It is passed an actual function call string generated by applyBehavior(), which
//may have a variable list of arguments, and this should return a matching mask.
//
//The return values are:
// URL : argument could be a file path, which DW will update during Save As...
// NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
// IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
// other...: argument is ignored

function identifyBehaviorArguments(fnCallStr) {
var argArray;

argArray = extractArgs(fnCallStr);
if (argArray.length == 7) {
return &quot;other,other,other,other,other,URL,URL&quot;;
} else {
return &quot;&quot;;
}
}



//Passed the function call above, takes prior arguments and reloads the UI.
//Converts strings into numbers for list indexes, and decodes URLs.

function inspectBehavior(argStr){
var argArray = extractArgs(argStr);

if (argArray.length == 7) { //function name plus 6 args
with (document.theForm) { // set all form values from args
NSJ.selectedIndex = parseInt(argArray[1]);
NSnoJ.selectedIndex = parseInt(argArray[2]);
IEJ.selectedIndex = parseInt(argArray[3]);
IEnoJ.selectedIndex = parseInt(argArray[4]);
OTHER.selectedIndex = parseInt(argArray[5]);
eURL.value = unescape(argArray[6]);
jURL.value = unescape(argArray[7]);
}
}
}


//**************** LOCAL FUNCTIONS ****************

function initializeUI() {
//not much to do here
}

Sawsie
 
Try changing the 'ja' to 'fr' . & then testing. don't know if the fr is the right one for french but worth a quick shot to test. Jessica [ponytails2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top