灵感来自Stephen Ostermiller在这里回答我的问题:https://webmasters.stackexchange.com/questions/53306/is-the-programmatic-addition-of-keywords-and-descriptions-worthwhile/53307?noredirect=1#comment53439_53307,我在这里找到了:Is it possible to use javascript to change the meta-tags of the page?这段代码:
$('meta[name=description]').remove();
$('head').append('<meta name="description" content="Find and optionally acquire all current and past Hugo award winning books">');
不幸的是,在将此代码添加到适当的位置(将Hugo奖项加载到页面中)时,当我运行新版本的网站并选择“查看页面源”时,我仍然会看到相同的旧描述:
<meta name="description" content="Find and optionally acquire all current and past book, movie, and music award winners, such as Pulitzers for books, Oscars/Academy Awards for movies, and Grammies for music, as well as many other awards" />
(并且它不在所有元标记的末尾,正如我希望的那样,如果我的代码有效)。
我在这里做错了什么或错过了什么?
答案 0 :(得分:1)
Google抓取工具使用Metatag,Google抓取工具不支持javascript 所以,你不能使用javascript设置元标记
答案 1 :(得分:1)
如果您只是想更改描述,那么更直接地执行此操作
$('meta[name="description"]').attr('content','new content');
我希望这就是你要找的东西。