作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
不幸的是,Weebly 没有提供使外部链接成为 noFollow 的方法。我联系了他们但没有结果,然后我在网上寻找这个脚本。
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'/>
<script type='text/javascript'>
//<![CDATA[
jQuery('a').each(function() {
// Let's make external links open in a new window.
var href = jQuery(this).attr('href');
if (typeof href != 'undefined' && href != "" && (href.indexOf('http://') != -1 ||
href.indexOf('https://') != -1) && href.indexOf(window.location.hostname) == -1) {
jQuery(this).attr("rel", "nofollow");
}
});
//]]>
</script>
但是,这段代码不起作用。您能告诉我出了什么问题或帮助我解决问题吗?谢谢。
最佳答案
Weebly 支持 JavaScript,但其实现方式与普通网络主机有所不同。
首先,将代码包装在 $(document).ready
中。然后,使用Custom HTML
元素将以下代码放置在您的页面中:
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
jQuery('a').each(function() {
// Let's make external links open in a new window.
var href = jQuery(this).attr('href');
if (typeof href != 'undefined' && href != "" && (href.indexOf('http://') != -1 ||
href.indexOf('https://') != -1) && href.indexOf(window.location.hostname) == -1) {
jQuery(this).attr("rel", "nofollow");
}
});
}
//]]>
</script>
据我所知,Weebly 已经在页面上为您包含了 jQuery,但如果没有,请转到 Settings
-> SEO
并添加 jQuery 脚本标签。这将使其显示在您的网站中 <head>
在 Weebly 上。
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'/>
关于javascript - 如何将 NoFollw 属性添加到我的所有 weebly 网站外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31899041/
我是一名优秀的程序员,十分优秀!