Connecting Tech Pros Worldwide Help | Site Map

changing meta tag with javascript

  #1  
Old August 29th, 2008, 07:01 PM
Newbie
 
Join Date: Oct 2007
Posts: 21
Hi
I have a scenario where I need to update meta tag content attribute at runtime using javascript .This is basically used for scenario where I m trying to integerate my application with facebook .Since facebook looks for meta tag I want to update those tags at runtime .
www.facebook.com/share_partners.php (Please go to this to see what I mean)

<meta name="title" content="Smith hails 'unique' Wable legacy" />
<meta name="description" content="John Smith claims beautiful football is the main legacy of Akhil Wable's decade at the club. " />
<link rel="image_src" href="http://www.onjd.com/design05/images/PH2/WableAFC205.jpg" />

For ex ,In above scenarios I want to update content attribute after page loads.

Also whether facebook will be able to read these updated values.(since SEO engines doesn't read )

Thanks
  #2  
Old August 29th, 2008, 10:02 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,493
Provided Answers: 10

re: changing meta tag with javascript


you can access the meta elements with
Expand|Select|Wrap|Line Numbers
  1. var meta = document.getElementsByTagName("meta");
then you can loop through the array and read/set the attribute values
Expand|Select|Wrap|Line Numbers
  1. var attrArray = meta[0].attributes;  // here: 1st meta element’s attributes
  2. var attrName = attrArray[0].nodeName; // get the name e.g. "name" (first attribute)
  3. attrArray[1].nodeValue = "new_attribute_value"; // set new value of "content" (2nd attribute)
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi, every one, anchor tag in li tag is problem, pls see it praveenb000 answers 1 September 6th, 2008 06:10 AM
Problem in Event Handling sorobor answers 2 July 11th, 2007 01:01 PM
Flickering while updation of Table using the XML tag flickers vanisathish@gmail.com answers 3 September 27th, 2005 08:15 AM
changing or at least detecting character encoding via javascript ? David Komanek answers 10 July 20th, 2005 11:51 AM