JavaScript (JS) hreflang Example: HTML DOM Objects – Anchor Object – JavaScript (JS) hreflang Example

JavaScript (JS) hreflang Example: HTML DOM Objects – Anchor Object – JavaScript (JS) hreflang Example

Purpose: – Illustrates the for the .

View Other Anchor Object Properties and Methods

Prerequistes:

Syntax: object.hreflang=languagecode – Allows you to retrieve or assign language for linked objects.

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:

  1. Use Visual Web Developer 2008
  2. Create new web site;
    • Click File/New Web Site
    • Select ASP.NET Website Template
    • Select C-Sharp for hrefuage
    • name of Web Site could be JavaScript_Syntax.
  3. Folder

  4. Add New folder named “HTMLDOMObjects”
    • Right-click project name in solution explorer;
    • add new folder;
    • name of folder should be: HTMLDOMObjects
  5. Add New subfolder to “HTMLDOMObjects” folder named “DOMAnchor”
    • Right-click folder named “HTMLDOMObjects” in solution explorer;
    • add new folder;
    • name of folder should be: DOMAnchor
  6. Add New subfolder to “DOMAnchor” subfolder named “AnchorObjectProperties”
    • Right-click subfolder named “DOMAnchor” in solution explorer;
    • add new folder;
    • name of folder should be: AnchorObjectProperties
  7. Add HTML Page Named hreflang to AnchorObjectProperties subfolder
    • Right-click AnchorObjectProperties subfolder;
    • add new item;
    • Select HTML Page
    • HTML Page name should be hreflang
  8. Click on copy code in code below to copy code into HTML Page hreflang.htm
  9. Right-click on HTML page hreflang.htm and select view in browser
View Example In Browser
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html>
  <head>
    <title>IdealProgrammer.com: hreflang </title>
    <!-- 
    ***************************************************
    * This example is from http://idealprogrammer.com *
    ***************************************************
   Here is a table of language codes:
   Sponsored Links
Kids Language Toys
Creative Games for Family Fun and Therapy. Free Shipping.
www.FunAndFunction.com
 
TEFL Course
Teach English as a Foreign Language Register and start studying today!
www.myteflworld.com
 
Sign Language Interpreter
Find Top Human Services Programs To Earn A Degree On Your Own Time.
www.Degrees-HumanServices.com
Name of Language ISO 639-1 Code 
Afar aa 
Abkhazian ab 
Afrikaans af 
Akan ak 
Albanian sq 
Amharic am 
Arabic ar 
Aragonese an 
Armenian hy 
Assamese as 
Avaric av 
Avestan ae 
Aymara ay 
Azerbaijani az 
Bashkir ba 
Bambara bm 
Basque eu 
Belarusian be 
Bengali bn 
Bihari bh 
Bislama bi 
Tibetan bo 
Bosnian bs 
Breton br 
Bulgarian bg 
Burmese my 
Catalan; Valencian ca 
Czech cs 
Chamorro ch 
Chechen ce 
Chinese zh 
Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic cu 
Chuvash cv 
Cornish kw 
Corsican co 
Cree cr 
Welsh cy 
Czech cs 
Danish da 
German de 
Divehi; Dhivehi; Maldivian dv 
Dutch; Flemish nl 
Dzongkha dz 
Greek, Modern (1453-) el 
English en 
Esperanto eo 
Estonian et 
Basque eu 
Ewe ee 
Faroese fo 
Persian fa 
Fijian fj 
Finnish fi 
French fr 
Western Frisian fy 
Fulah ff 
Georgian ka 
German de 
Gaelic; Scottish Gaelic gd 
Irish ga 
Galician gl 
Manx gv 
Greek, Modern (1453-) el 
Guarani gn 
Gujarati gu 
Haitian; Haitian Creole ht 
Hausa ha 
Hebrew he 
Herero hz 
Hindi hi 
Hiri Motu ho 
Croatian hr 
Hungarian hu 
Armenian hy 
Igbo ig 
Icelandic is 
Ido io 
Sichuan Yi ii 
Inuktitut iu 
Interlingue ie 
Interlingua (International Auxiliary Language Association) ia 
Indonesian id 
Inupiaq ik 
Icelandic is 
Italian it 
Javanese jv 
Japanese ja 
Kalaallisut; Greenlandic kl 
Kannada kn 
Kashmiri ks 
Georgian ka 
Kanuri kr 
Kazakh kk 
Central Khmer km 
Kikuyu; Gikuyu ki 
Kinyarwanda rw 
Kirghiz; Kyrgyz ky 
Komi kv 
Kongo kg 
Korean ko 
Kuanyama; Kwanyama kj 
Kurdish ku 
Lao lo 
Latin la 
Latvian lv 
Limburgan; Limburger; Limburgish li 
Lingala ln 
Lithuanian lt 
Luxembourgish; Letzeburgesch lb 
Luba-Katanga lu 
Ganda lg 
Macedonian mk 
Marshallese mh 
Malayalam ml 
Maori mi 
Marathi mr 
Malay ms 
Macedonian mk 
Malagasy mg 
Maltese mt 
Moldavian mo 
Mongolian mn 
Maori mi 
Malay ms 
Burmese my 
Nauru na 
Navajo; Navaho nv 
Ndebele, South; South Ndebele nr 
Ndebele, North; North Ndebele nd 
Ndonga ng 
Nepali ne 
Dutch; Flemish nl 
Norwegian Nynorsk; Nynorsk, Norwegian nn 
Bokmål, Norwegian; Norwegian Bokmål nb 
Norwegian no 
Chichewa; Chewa; Nyanja ny 
Occitan (post 1500); Provençal oc 
Ojibwa oj 
Oriya or 
Oromo om 
Ossetian; Ossetic os 
Panjabi; Punjabi pa 
Persian fa 
Pali pi 
Polish pl 
Portuguese pt 
Pushto ps 
Quechua qu 
Romansh rm 
Romanian ro 
Romanian ro 
Rundi rn 
Russian ru 
Sango sg 
Sanskrit sa 
Serbian sr 
Croatian hr 
Sinhala; Sinhalese si 
Slovak sk 
Slovak sk 
Slovenian sl 
Northern Sami se 
Samoan sm 
Shona sn 
Sindhi sd 
Somali so 
Sotho, Southern st 
Spanish; Castilian es 
Albanian sq 
Sardinian sc 
Serbian sr 
Swati ss 
Sundanese su 
Swahili sw 
Swedish sv 
Tahitian ty 
Tamil ta 
Tatar tt 
Telugu te 
Tajik tg 
Tagalog tl 
Thai th 
Tibetan bo 
Tigrinya ti 
Tonga (Tonga Islands) to 
Tswana tn 
Tsonga ts 
Turkmen tk 
Turkish tr 
Twi tw 
Uighur; Uyghur ug 
Ukrainian uk 
Urdu ur 
Uzbek uz 
Venda ve 
Vietnamese vi 
Volapük vo 
Welsh cy 
Walloon wa 
Wolof wo 
Xhosa xh 
Yiddish yi 
Yoruba yo 
Zhuang; Chuang za 
Chinese zh 
Zulu zu 
 
 
    -->
 
 
 
   </head>
  <body>
      <a href="http://www.google.com" hreflang="en" id="Google">Google</a><br /><br />
      <a href="http://www.yahoo.com" hreflang="fr" id="Yahoo">Yahoo</a><br /><br />
      <a href="http://idealprogrammer.com" hreflang="de" id="IdealProgrammer">IdealProgrammer</a><br /><br />
      <a href="http://myqol.com" hreflang="hi" id="ProgressMonitor">ProgressMonitor</a><br /><br />
 
   <script type="text/javascript">
       //*****************************************************
       // DOM Objects
       //*****************************************************
 
 
       //*****************************************************
       //    ***    Anchor Object Properties   ***
       //*****************************************************
 
       //*****************************************************
       // href
       //*****************************************************
 
       //    SYNTAX:
       //    object.href=hreflang  Allows you to retrieve or assign  
       //               language to linked object
 
       // Two ways to retrieve hreflang   
       //   1. GetElementsByTagName
            myObject=document.getElementsByTagName('a')[0];
            document.write("Google - Using getElementsByTagName : " + myObject.hreflang);
            document.write("<br />");
      //   2. GetElementById
            document.write("Yahoo - Using getElementById: ");
            document.write(document.getElementById('Yahoo').hreflang);
 
            document.write("<br /><br />");
       // Two ways to assign hreflang
 
            //   1. GetElementById
            myThirdElement = document.getElementById('IdealProgrammer');
            myThirdElement.hreflang = "de";
            document.write("<br />IdealProgrammer href changed to German: ", myThirdElement.hreflang);
 
       //   2. GetElementsByTagName      
            myFourthElement = document.getElementsByTagName('a')[3];
            myFourthElement.hreflang = "en";
            document.write("<br />ProgressMonitor href changed to English: ", myFourthElement.hreflang)
 
</script>
 
  </body>
</html>