Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old August 29th, 2008, 07:01 PM
Newbie
 
Join Date: Oct 2007
Posts: 21
Default changing meta tag with javascript

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
Reply
  #2  
Old August 29th, 2008, 10:02 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 31
Posts: 895
Default

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.