用javascript或jquery替换现有的规范标记 [英] Replace existing canonical tag with javascript or jquery

查看:148
本文介绍了用javascript或jquery替换现有的规范标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Adobe Muse创建一个小部件,替换Muse自动生成的规范标签。

I'm wanting to create a widget for Adobe Muse that replaces the canonical tags that Muse automatically generates.

我知道这对大多数机器人不起作用,因为它们在抓取页面时不运行任何脚本,但我已经读过Google的机器人在爬行时会运行脚本。

I know that this will not work with most bots because they don't run any scripts when crawling pages, but I have read that Google's bot does run scripts when it crawls.

我发现很多关于如何从链接中替换href的问题,但我似乎无法找到有关替换规范标记的href URL的任何问题。我几乎肯定这是我开始的地方......我只是不知道如何完成它:

I found many questions on how to replace the href from a links but I couldn't seem to find any questions on replacing the href URL of a canonical tag. I'm almost positive this is where I start... I just don't know how to finish it:

<script>
    $(document).ready(function() {
         $('link[rel=canonical]').attr('href' 'NEW_LINK');
    }
</script>


推荐答案

$('link[rel="canonical"]').attr('href', 'NEW_HREF_GOES_HERE');

这篇关于用javascript或jquery替换现有的规范标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆