-1

I am changing my meta description content in javascript but i m unable to do that. javascript code

window.onload = function () {
     setProductMeta();
 }
function setProductMeta(){
 document.getElementById("description").setAttribute("content",
"dynamic meta description");
}

<meta id="description" name="description" content="" />

What should i change to let it working

user3575612
  • 53
  • 1
  • 8
  • possible duplicate of [Is it possible to use javascript to change the meta-tags of the page?](http://stackoverflow.com/questions/2568760/is-it-possible-to-use-javascript-to-change-the-meta-tags-of-the-page) – benomatis Apr 26 '14 at 11:12
  • tried the solutions.but didnt wrk.any help if u can do this... – user3575612 Apr 26 '14 at 11:24
  • what solution? the accepted answer is actually saying it's useless to do, have another look... – benomatis Apr 26 '14 at 11:27
  • please help me with solution to this.dnt bother how i m going to use it. – user3575612 Apr 26 '14 at 11:30
  • @webeno that answer is 4 years old. Javascript used to be considered useless other than annoying and abusing users. Developers, advertisers, and companies are always finding new uses for technologies. It's not healthy to immediately to right something off because someone else years ago deemed it silly. – skzryzg Apr 26 '14 at 12:44
  • @webeno i take that back. I had too much faith in his goals. The dipshit was just wanting to do exactly what everyone had said was pointless...either that or he wasn't reading what everyone suggested – skzryzg Apr 26 '14 at 13:26
  • @skzryzg-no need to comment on anything child.i have to utilize it in my way...so be calm and control your damm shit..... – user3575612 Apr 26 '14 at 13:31

1 Answers1

0

Conventional wisdom says this is a pointless task, but that's pretty much only true for search engines. You never know when other websites will figure out a new use for the meta tags. So it's not as pointless of an exercise as some would tell you.

remember, the DOM won't always be updated in the source code, so check with your favorite developer tools.

var meta = document.getElementsByName("description")[0]; //this assumes there is only one description
meta.setAttribute("content", "new description");// set description

Or, if you want to use jquery:

$('meta[name=description]').attr('content', 'super awesome description');
skzryzg
  • 1,020
  • 8
  • 25
  • in alerts i m able to see,but how can we in source code sir. – user3575612 Apr 26 '14 at 12:06
  • that's entirely browser dependent – skzryzg Apr 26 '14 at 12:08
  • @user3575612 for example in chrome, you can use the developer tools and look under "Elements" to see changes being made live – skzryzg Apr 26 '14 at 12:10
  • k.but when we go live with the code.we will be able to provide meta description,ryt? – user3575612 Apr 26 '14 at 12:40
  • sry,i mean to say it will be crawlable,is it? – user3575612 Apr 26 '14 at 12:54
  • 1
    have you seriously not been paying attention to everyone who has been saying that this is a pointless task, particularly for search engines? Hint: search engines CRAWL your website to index it. And no, it's not crawlable because of the exact nature of how websites work. Javascript modifies the the source after it is rendered. Crawlers dont render javascript because there's no point. – skzryzg Apr 26 '14 at 12:58