vchris 3 Posted April 1, 2007 Report Share Posted April 1, 2007 I need to get the language from a file. My files are named bla_e.php and bla_f.php. How can I identify the language in javascript? Quote Link to post Share on other sites
vchris 3 Posted April 2, 2007 Author Report Share Posted April 2, 2007 Or do you know how to get only the filename? Quote Link to post Share on other sites
aspnetguy 30 Posted April 2, 2007 Report Share Posted April 2, 2007 var url = window.location;var lang = "";if(url.indexOf("_e.php") != -1) lang = "english";else if(url.indexOf("_f.php") != -1) lang = "french";else lang = "unknown"; Quote Link to post Share on other sites
vchris 3 Posted April 3, 2007 Author Report Share Posted April 3, 2007 Thanks!Always wondered are the { and } optional in javascript? Quote Link to post Share on other sites
aspnetguy 30 Posted April 3, 2007 Report Share Posted April 3, 2007 only if you have 1 line followinglike if(condition) dosomething();//orif(condition) dosomething();//unexpected resultif(condition) doSomething(); do somethingElse();//what the above is really doingif(condition){ dosomething();}dosomethingElse(); Quote Link to post Share on other sites
vchris 3 Posted April 6, 2007 Author Report Share Posted April 6, 2007 var url = window.location;var lang = "";if(url.indexOf("_e.php") != -1) lang = "english";else if(url.indexOf("_f.php") != -1) lang = "french";else lang = "unknown"; I tried your code but I get javascript errors. It says that url.indexOf is not a function. Then I tried url.search and it said the same thing... Quote Link to post Share on other sites
Bassam122 0 Posted April 9, 2007 Report Share Posted April 9, 2007 I tried your code but I get javascript errors. It says that url.indexOf is not a function. Then I tried url.search and it said the same thing...hi,first try to assign the var url the value window.location.href(var url = window.location.href) then try the codew again. Quote Link to post Share on other sites
vchris 3 Posted April 10, 2007 Author Report Share Posted April 10, 2007 Works perfect! thanks! Quote Link to post Share on other sites
aspnetguy 30 Posted April 10, 2007 Report Share Posted April 10, 2007 Thanks for catching that. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.