Jump to content

  • Free consultations and support
  • Live chatClick Here for Live Chat
  • Call ico 1888-906-1888
    Phone support: Open

    Ready for your call :)

    Our business hours:

    Mon — Fri, 2am — 8pm (EST)

    US & EU support teams

    Phone support: Closed

    We are back in: 1h 20m

    Our business hours:

    Mon — Fri, 2am — 8pm (EST)

    US & EU support teams


Checking for Meta Tag Values in JavaScript

javascript meta tag values

  • Please log in to reply
 

#1 SmartWeb

SmartWeb

    Senior Member

  • Designer
  • 271 posts

Posted 06 December 2012 - 11:02 PM

To check for Meta Tags values in JavaScript:
1.Open your text editor and make a new file and name it "metaTags.html." Add HTML tags in your file.
<html>
<head></head>
<body></body>
</html>
2.Add meta tags in the file between "<head>" and "</head>". Name the first meta tag meta1 , second meta2 and third meta3 using the name property <html>.
<head>
<title></title>
<meta name="meta1">
<meta name="meta2">
<meta name="meta3">
</head>
<body></body>
</html>
3.Assign content values to the meta tags. <html>. Also add a Javascript script tag between <body> </body> tags.

<head>
<title></title>
<meta name="meta1" content="firstval">
<meta name="meta2" content="secval">
<meta name="meta3" content="thirdval">
</head>
<body>
<script type="text/javascript">
</script>
</body>
</html>
4. Set your script's type value as text/javascript and then add </script>."
<body>
<script type="text/javascript">
</script>
</body>
5.Use the Javascript method getElementsByTagName() to retrieve your meta tag values.
<body>
<script type="text/javascript">
var mTags = document.getElementsByTagName('meta');
</script>
</body>
6 to determine the meta tag count use the Javascript length method
<body>
<script type="text/javascript">
var metaTags = document.getElementsByTagName('meta');
var metaTagLength=metaTags.length;
</script>
</body>
7.Using the metatagLength you can create a Javascript loop to loop the meta tag values.

<body>
<script type="text/javascript">
var metaTags = document.getElementsByTagName('meta');
var metaTagLength=metaTags.length;
for(var i=0;i<metaTagLength;i++)
{
}
</script>
</body>
8.to write the meta tag contents to the page use document.write
<body>
<script type="text/javascript">
var metaTags = document.getElementsByTagName('meta');
var metaTagLength=metaTags.length;
for(var i=0;i<metaTagLength;i++)
{
document.write(metaTags[i].content);
}
</script>
</body>
9 .Open metaTags.html in a browser. Check that each meta tag value is written to the page.





Also tagged with one or more of these keywords: javascript, meta tag values

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users