Подскажите как добавить атрибут rel="nofollow" к ссылке
Здравствуйте,
Подскажите как по средством js добавить к ссылки rel="nofollow. Возможно ли перехватить ссылку и добавить к ней атрибут Сейчас ссылка такого вида <a href="/kontakty.html">Контакты </a> необходима такая <a href="/kontakty.html" rel="nofollow">Контакты </a> Что то вроде этого <script> (function() { var script, scripts = document.getElementsByTagName('script')[0]; function load(url) { script = document.createElement('script'); script.async = true; script.src = url; scripts.parentNode.insertBefore(script, scripts); } load('/media/js/watch.js'); load('/media/js/top100.js'); load('/media/js/code.js'); }()); </script> но для ссылок |
Stas1985,
<a href="/kontakty.html">Контакты </a> <script> [].forEach.call(document.querySelectorAll('a'), function(a) { a.setAttribute('rel', 'nofollow') }) </script> |
Так тут и проблема.
В меню куча других ссылок а мне необходимо только для kontakty.html |
<a href="/fafa.html">Контакты </a> <a href="/kontakty.html">Контакты </a> <a href="/blabla.html">Контакты </a> <a href="/haha.html">Контакты </a> <script> [].forEach.call(document.querySelectorAll('a[href$="kontakty.html"]'), function(a) { a.setAttribute('rel', 'nofollow') }) </script> |
Подскажите, если я хочу подключить несколько ссылок
<script> [].forEach.call(document.querySelectorAll('a[href$="kontakty.html"]', 'a[href$="o-kompanii.html"]', 'a[href$="vakansii.html"]'), function(a) { a.setAttribute('rel', 'nofollow') }) </script> правильный вариант я делаю |
[].forEach.call(document.querySelectorAll('a[href$="kontakty.html"], a[href$="o-kompanii.html"], a[href$="vakansii.html"]'), function(a) { a.setAttribute('rel', 'nofollow') }); |
Если использую ваш вариант
<script> [].forEach.call(document.querySelectorAll('a[href$="kontakty.html"], a[href$="o-kompanii.html"], a[href$="vakansii.html"]'), function(a) { a.setAttribute('rel', 'nofollow') }); </script> Получаю в еонсоли JQMIGRATE: Migrate is installed, version 1.4.1 Метод getAttributeNode() является устаревшим. Для его замены используйте метод getAttribute(). Пустая строка не может быть аргументом метода getElementById(). Пустая строка не может быть аргументом метода getElementById(). Если использую свой <script> [].forEach.call(document.querySelectorAll('a[href$="kontakty.html"]'),function(a) {a.setAttribute('rel','nofollow')}); [].forEach.call(document.querySelectorAll('a[href$="o-kompanii.html"]'),function(a) {a.setAttribute('rel','nofollow')}); [].forEach.call(document.querySelectorAll('a[href$="vakansii.html"]'),function(a) {a.setAttribute('rel','nofollow')}); </script> то получаю JQMIGRATE: Migrate is installed, version 1.4.1 Метод getAttributeNode() является устаревшим. Для его замены используйте метод getAttribute(). Подскажите что это за ошибки |
Это вообще из другой оперы, во всяком случае обновите библиотеки ваши, и все скрипты что отвалятся с ними обновите тоже.
|
Часовой пояс GMT +3, время: 03:08. |