JavaScript (JS) lang Example: HTML DOM Objects – Body Object – JavaScript (JS) lang Example
| .NET | .NET Programming (C# or VB) (Web or Desktop) | |||
| Key Supporting Languages | HTML | CSS | JavaScript | SQL Server |
| Access | AJAX | ASP | Blogging | ColdFusion |
| Expression Blend | mySQL | Perl | PHP | Ruby |
| SEO | SharePoint | Silverlight | Web Design | Web Dev |
JavaScript (JS) lang Example: HTML DOM Objects – Body Object – JavaScript (JS) lang Example
Purpose: – Illustrates the JavaScript syntax for the Body Object lang Property .
Prerequistes:
- Install Visual Web Developer 2008
Syntax: BodyObject.lang="langname" – Allows you to access the language for a BodyObject.
Restrictions: None
Notes:
- You can build your own library of syntax examples by using same web site over and over and just add new files to it.
Instructions:
- Use Visual Web Developer 2008
- Create new web site;
- Click File/New Web Site
- Select ASP.NET Website Template
- Select C-Sharp for language
- name of Web Site could be JavaScript_Syntax.
- Add New folder named "HTMLDOMObjects"
- Right-click project name in solution explorer;
- add new folder;
- name of folder should be: HTMLDOMObjects
- Add New subfolder to "HTMLDOMObjects" folder named "DOMBody"
- Right-click folder named "HTMLDOMObjects" in solution explorer;
- add new folder;
- name of folder should be: DOMBody
- Add New subfolder to "DOMBody" subfolder named "BodyObjectProperties"
- Right-click subfolder named "DOMBody" in solution explorer;
- add new folder;
- name of folder should be: BodyObjectProperties
- Add HTML Page Named lang to BodyObjectProperties subfolder
- Right-click BodyObjectProperties subfolder;
- add new item;
- Select HTML Page
- HTML Page name should be lang
- Click on copy code in code below to copy code into HTML Page lang.htm
- Right-click on HTML page lang.htm and select view in browser
| HTML | | copy code | | ? |
| 001 | |
| 002 | < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 003 | |
| 004 | <html> |
| 005 | <head> |
| 006 | <title>IdealProgrammer.com: lang </title> |
| 007 | <!-- |
| 008 | *************************************************** |
| 009 | * This example is from http://idealprogrammer.com * |
| 010 | *************************************************** |
| 011 | --> |
| 012 | <style type="text/css" id="myStyle"> |
| 013 | |
| 014 | .myButtons |
| 015 | { |
| 016 | font-size:large; |
| 017 | color:red; |
| 018 | } |
| 019 | .myButtons input |
| 020 | { |
| 021 | color:Blue |
| 022 | } |
| 023 | |
| 024 | .myButton2 |
| 025 | { |
| 026 | font-size:small; |
| 027 | } |
| 028 | .myButton2 input |
| 029 | { |
| 030 | font-style :italic |
| 031 | } |
| 032 | |
| 033 | .myButton3 |
| 034 | { |
| 035 | background-color:#d0e4fe; |
| 036 | } |
| 037 | .myButton3 input |
| 038 | { |
| 039 | font-weight:600 |
| 040 | } |
| 041 | |
| 042 | |
| 043 | </style> |
| 044 | <script type="text/javascript"> |
| 045 | |
| 046 | //**************************************************************** |
| 047 | // Set Cookie |
| 048 | //**************************************************************** |
| 049 | function Set_Cookie( name, value, expires, path, domain, secure ) |
| 050 | { |
| 051 | // set time, it's in milliseconds |
| 052 | var today = new Date(); |
| 053 | today.setTime( today.getTime() ); |
| 054 | |
| 055 | /* |
| 056 | if the expires variable is set, make the correct |
| 057 | expires time, the current script below will set |
| 058 | it for x number of days, to make it for hours, |
| 059 | delete * 24, for minutes, delete * 60 * 24 |
| 060 | */ |
| 061 | if ( expires ) |
| 062 | { |
| 063 | expires = expires * 1000 * 60 * 60 * 24; |
| 064 | } |
| 065 | var expires_date = new Date( today.getTime() + (expires) ); |
| 066 | |
| 067 | document.cookie = name + "=" +escape( value ) + |
| 068 | ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + |
| 069 | ( ( path ) ? ";path=" + path : "" ) + |
| 070 | ( ( domain ) ? ";domain=" + domain : "" ) + |
| 071 | ( ( secure ) ? ";secure" : "" ); |
| 072 | } |
| 073 | |
| 074 | //**************************************************************** |
| 075 | // Get Cookie |
| 076 | //**************************************************************** |
| 077 | // this fixes an issue with the old method, ambiguous values |
| 078 | // with this test document.cookie.indexOf( name + "=" ); |
| 079 | function Get_Cookie(check_name) { |
| 080 | // first we'll split this cookie up into name/value pairs |
| 081 | // note: document.cookie only returns name=value, not the other components |
| 082 | var a_all_cookies = document.cookie.split(';'); |
| 083 | var a_temp_cookie = ''; |
| 084 | var cookie_name = ''; |
| 085 | var cookie_value = ''; |
| 086 | var b_cookie_found = false; // set boolean t/f default f |
| 087 | |
| 088 | for (i = 0; i < a_all_cookies.length; i++) { |
| 089 | // now we'll split apart each name=value pair |
| 090 | a_temp_cookie = a_all_cookies[i].split('='); |
| 091 | |
| 092 | |
| 093 | // and trim left/right whitespace while we're at it |
| 094 | cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, ''); |
| 095 | |
| 096 | // if the extracted name matches passed check_name |
| 097 | if (cookie_name == check_name) { |
| 098 | b_cookie_found = true; |
| 099 | // we need to handle case where cookie has no value but exists (no = sign, that is): |
| 100 | if (a_temp_cookie.length > 1) { |
| 101 | cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, '')); |
| 102 | } |
| 103 | // note that in cases where cookie is initialized but no value, null is returned |
| 104 | return cookie_value; |
| 105 | break; |
| 106 | } |
| 107 | a_temp_cookie = null; |
| 108 | cookie_name = ''; |
| 109 | } |
| 110 | if (!b_cookie_found) { |
| 111 | return null; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | </script> |
| 116 | |
| 117 | </head> |
| 118 | <body id="myBodyID" class="myButtons" lang="en"> |
| 119 | |
| 120 | Please click Buttons to change lang assigned to body:<br /><br /> |
| 121 | <!--using onclick to set a cookie and reload page; |
| 122 | when page is reloading, we check that cookie to assign different styles to body |
| 123 | --> |
| 124 | <input id="Button1" type="button" value="button" onclick="javascript: Set_Cookie( 'mycookie', '1', 30, '/', '', '' ); window.location.reload();" /><br /><br /> |
| 125 | <input id="Button2" type="button" value="button - es" onclick="javascript: Set_Cookie( 'mycookie', '2', 30, '/', '', '' ); window.location.reload();"/><br /><br /> |
| 126 | <input id="Button3" type="button" value="button - fr" onclick="javascript: Set_Cookie( 'mycookie', '3', 30, '/', '', '' ); window.location.reload();"/><br /><br /> |
| 127 | <script type="text/javascript"> |
| 128 | //***************************************************** |
| 129 | // DOM Objects |
| 130 | //***************************************************** |
| 131 | |
| 132 | |
| 133 | //***************************************************** |
| 134 | // *** Body Object Properties *** |
| 135 | //***************************************************** |
| 136 | |
| 137 | //***************************************************** |
| 138 | // lang |
| 139 | //***************************************************** |
| 140 | |
| 141 | // SYNTAX: |
| 142 | // object.lang="lang" Allows you to retrieve or assign lang for |
| 143 | // body |
| 144 | // Here is a table of language codes: |
| 145 | //Name of Language ISO 639-1 Code |
| 146 | //Afar aa |
| 147 | //Abkhazian ab |
| 148 | //Afrikaans af |
| 149 | //Akan ak |
| 150 | //Albanian sq |
| 151 | //Amharic am |
| 152 | //Arabic ar |
| 153 | //Aragonese an |
| 154 | //Armenian hy |
| 155 | //Assamese as |
| 156 | //Avaric av |
| 157 | //Avestan ae |
| 158 | //Aymara ay |
| 159 | //Azerbaijani az |
| 160 | //Bashkir ba |
| 161 | //Bambara bm |
| 162 | //Basque eu |
| 163 | //Belarusian be |
| 164 | //Bengali bn |
| 165 | //Bihari bh |
| 166 | //Bislama bi |
| 167 | //Tibetan bo |
| 168 | //Bosnian bs |
| 169 | //Breton br |
| 170 | //Bulgarian bg |
| 171 | //Burmese my |
| 172 | //Catalan; Valencian ca |
| 173 | //Czech cs |
| 174 | //Chamorro ch |
| 175 | //Chechen ce |
| 176 | //Chinese zh |
| 177 | //Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic cu |
| 178 | //Chuvash cv |
| 179 | //Cornish kw |
| 180 | //Corsican co |
| 181 | //Cree cr |
| 182 | //Welsh cy |
| 183 | //Czech cs |
| 184 | //Danish da |
| 185 | //German de |
| 186 | //Divehi; Dhivehi; Maldivian dv |
| 187 | //Dutch; Flemish nl |
| 188 | //Dzongkha dz |
| 189 | //Greek, Modern (1453-) el |
| 190 | //English en |
| 191 | //Esperanto eo |
| 192 | //Estonian et |
| 193 | //Basque eu |
| 194 | //Ewe ee |
| 195 | //Faroese fo |
| 196 | //Persian fa |
| 197 | //Fijian fj |
| 198 | //Finnish fi |
| 199 | //French fr |
| 200 | //Western Frisian fy |
| 201 | //Fulah ff |
| 202 | //Georgian ka |
| 203 | //German de |
| 204 | //Gaelic; Scottish Gaelic gd |
| 205 | //Irish ga |
| 206 | //Galician gl |
| 207 | //Manx gv |
| 208 | //Greek, Modern (1453-) el |
| 209 | //Guarani gn |
| 210 | //Gujarati gu |
| 211 | //Haitian; Haitian Creole ht |
| 212 | //Hausa ha |
| 213 | //Hebrew he |
| 214 | //Herero hz |
| 215 | //Hindi hi |
| 216 | //Hiri Motu ho |
| 217 | //Croatian hr |
| 218 | //Hungarian hu |
| 219 | //Armenian hy |
| 220 | //Igbo ig |
| 221 | //Icelandic is |
| 222 | //Ido io |
| 223 | //Sichuan Yi ii |
| 224 | //Inuktitut iu |
| 225 | //Interlingue ie |
| 226 | //Interlingua (International Auxiliary Language Association) ia |
| 227 | //Indonesian id |
| 228 | //Inupiaq ik |
| 229 | //Icelandic is |
| 230 | //Italian it |
| 231 | //Javanese jv |
| 232 | //Japanese ja |
| 233 | //Kalaallisut; Greenlandic kl |
| 234 | //Kannada kn |
| 235 | //Kashmiri ks |
| 236 | //Georgian ka |
| 237 | //Kanuri kr |
| 238 | //Kazakh kk |
| 239 | //Central Khmer km |
| 240 | //Kikuyu; Gikuyu ki |
| 241 | //Kinyarwanda rw |
| 242 | //Kirghiz; Kyrgyz ky |
| 243 | //Komi kv |
| 244 | //Kongo kg |
| 245 | //Korean ko |
| 246 | //Kuanyama; Kwanyama kj |
| 247 | //Kurdish ku |
| 248 | //Lao lo |
| 249 | //Latin la |
| 250 | //Latvian lv |
| 251 | //Limburgan; Limburger; Limburgish li |
| 252 | //Lingala ln |
| 253 | //Lithuanian lt |
| 254 | //Luxembourgish; Letzeburgesch lb |
| 255 | //Luba-Katanga lu |
| 256 | //Ganda lg |
| 257 | //Macedonian mk |
| 258 | //Marshallese mh |
| 259 | //Malayalam ml |
| 260 | //Maori mi |
| 261 | //Marathi mr |
| 262 | //Malay ms |
| 263 | //Macedonian mk |
| 264 | //Malagasy mg |
| 265 | //Maltese mt |
| 266 | //Moldavian mo |
| 267 | //Mongolian mn |
| 268 | //Maori mi |
| 269 | //Malay ms |
| 270 | //Burmese my |
| 271 | //Nauru na |
| 272 | //Navajo; Navaho nv |
| 273 | //Ndebele, South; South Ndebele nr |
| 274 | //Ndebele, North; North Ndebele nd |
| 275 | //Ndonga ng |
| 276 | //Nepali ne |
| 277 | //Dutch; Flemish nl |
| 278 | //Norwegian Nynorsk; Nynorsk, Norwegian nn |
| 279 | //Bokmål, Norwegian; Norwegian Bokmål nb |
| 280 | //Norwegian no |
| 281 | //Chichewa; Chewa; Nyanja ny |
| 282 | //Occitan (post 1500); Provençal oc |
| 283 | //Ojibwa oj |
| 284 | //Oriya or |
| 285 | //Oromo om |
| 286 | //Ossetian; Ossetic os |
| 287 | //Panjabi; Punjabi pa |
| 288 | //Persian fa |
| 289 | //Pali pi |
| 290 | //Polish pl |
| 291 | //Portuguese pt |
| 292 | //Pushto ps |
| 293 | //Quechua qu |
| 294 | //Romansh rm |
| 295 | //Romanian ro |
| 296 | //Romanian ro |
| 297 | //Rundi rn |
| 298 | //Russian ru |
| 299 | //Sango sg |
| 300 | //Sanskrit sa |
| 301 | //Serbian sr |
| 302 | //Croatian hr |
| 303 | //Sinhala; Sinhalese si |
| 304 | //Slovak sk |
| 305 | //Slovak sk |
| 306 | //Slovenian sl |
| 307 | //Northern Sami se |
| 308 | //Samoan sm |
| 309 | //Shona sn |
| 310 | //Sindhi sd |
| 311 | //Somali so |
| 312 | //Sotho, Southern st |
| 313 | //Spanish; Castilian es |
| 314 | //Albanian sq |
| 315 | //Sardinian sc |
| 316 | //Serbian sr |
| 317 | //Swati ss |
| 318 | //Sundanese su |
| 319 | //Swahili sw |
| 320 | //Swedish sv |
| 321 | //Tahitian ty |
| 322 | //Tamil ta |
| 323 | //Tatar tt |
| 324 | //Telugu te |
| 325 | //Tajik tg |
| 326 | //Tagalog tl |
| 327 | //Thai th |
| 328 | //Tibetan bo |
| 329 | //Tigrinya ti |
| 330 | //Tonga (Tonga Islands) to |
| 331 | //Tswana tn |
| 332 | //Tsonga ts |
| 333 | //Turkmen tk |
| 334 | //Turkish tr |
| 335 | //Twi tw |
| 336 | //Uighur; Uyghur ug |
| 337 | //Ukrainian uk |
| 338 | //Urdu ur |
| 339 | //Uzbek uz |
| 340 | //Venda ve |
| 341 | //Vietnamese vi |
| 342 | //Volapük vo |
| 343 | //Welsh cy |
| 344 | //Walloon wa |
| 345 | //Wolof wo |
| 346 | //Xhosa xh |
| 347 | //Yiddish yi |
| 348 | //Yoruba yo |
| 349 | //Zhuang; Chuang za |
| 350 | //Chinese zh |
| 351 | //Zulu zu |
| 352 | //***************************************************** |
| 353 | // Two ways to retrieve lang |
| 354 | //***************************************************** |
| 355 | document.write("<strong>Demonstrating Two Ways to Retrieve Property</strong><br />") |
| 356 | // 1. GetElementsByTagName |
| 357 | myObject=document.getElementsByTagName('body')[0]; |
| 358 | document.write("1. Using getElementsByTagName: " + myObject.lang); |
| 359 | document.write("<br />"); |
| 360 | // 2. GetElementById |
| 361 | |
| 362 | document.write("2. Using getElementById: "); |
| 363 | document.write(document.getElementById('myBodyID').lang); |
| 364 | document.write("<br />"); |
| 365 | document.write("<br />"); |
| 366 | |
| 367 | |
| 368 | |
| 369 | //***************************************************** |
| 370 | // Two ways to assign lang |
| 371 | //***************************************************** |
| 372 | // using cookies to change property and style on the fly |
| 373 | if (Get_Cookie('mycookie')) { |
| 374 | |
| 375 | ButtonNum = (Get_Cookie('mycookie')); |
| 376 | } |
| 377 | else { |
| 378 | ButtonNum = '1'; |
| 379 | } |
| 380 | |
| 381 | // 1. GetElementById |
| 382 | |
| 383 | if (ButtonNum !== '1') |
| 384 | { |
| 385 | document.write("<strong>(We are retrieving before assigning new value)</strong><br />"); |
| 386 | } |
| 387 | |
| 388 | if (ButtonNum == '2') { |
| 389 | document.write("<strong>Demonstrating Assigning Property with GetById</strong><br />") |
| 390 | document.getElementById('myBodyID').className = "myButton2" |
| 391 | document.getElementById('myBodyID').lang = "es" |
| 392 | document.write("Body lang changed to lang: " + document.getElementById('myBodyID').lang + "<br />"); |
| 393 | } |
| 394 | // 2. GetElementsByTagName |
| 395 | |
| 396 | if (ButtonNum == '3') { |
| 397 | document.write("<strong>Demonstrating Assigning Property with GetElementsByTagName</strong><br />") |
| 398 | myThirdButton = document.getElementsByTagName('body')[0]; |
| 399 | myThirdButton.className = "myButton3"; |
| 400 | myThirdButton.lang = "fr"; |
| 401 | document.write("Body lang changed to fr: " + myThirdButton.lang); |
| 402 | |
| 403 | } |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | </script> |
| 409 | |
| 410 | </body> |
| 411 | </html> |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 |
Related posts:
- JavaScript (JS) dir Example: HTML DOM Objects – Body Object – JavaScript (JS) dir Example JavaScript (JS) dir Example: HTML DOM Objects - Body Object...
- JavaScript (JS) id Example: HTML DOM Objects – Body Object – JavaScript (JS) id Example JavaScript (JS) id Example: HTML DOM Objects - Body Object...
- JavaScript (JS) className Example: HTML DOM Objects – Body Object – JavaScript (JS) className Example JavaScript (JS) className Example: HTML DOM Objects - Body Object...
- JavaScript (JS) title Example: HTML DOM Objects – Body Object – (JS) JavaScript title Example HTML DOM Objects - Body Object - JavaScript title Example...
- lang Example JavaScript (JS): HTML DOM Objects – Button Object – lang Example JavaScript (JS) lang Example JavaScript (JS): HTML DOM Objects - Button Object...
Related posts brought to you by Yet Another Related Posts Plugin.

Comments
One Response to “JavaScript (JS) lang Example: HTML DOM Objects – Body Object – JavaScript (JS) lang Example”Trackbacks
Check out what others are saying about this post...[...] posted here: HTML DOM Objects – Body Object – JavaScript lang Example … Share and [...]