昨天我問了類似的問題,所以我知道如何將所有外部鏈接重定向到我的主頁。重定向除了我不想重定向的所有外部鏈接
// when the document is ready
$(document).ready(function() {
// iterate over all the anchor tags
$("a").each(function() {
// if the current link's href doesn't already contain 'www.kownleg.com'
if (this.href.indexOf('www.kownleg.com') === -1) {
// change current link to home page
this.href = 'http://www.kownleg.com';
}
});
});
但現在我要排除所有這些我不想重定向到我的主頁,像facebook.com & twitter.com的聯繫,我試圖讓該鏈接的另一個條件,我不要不想重定向,但它不起作用。然後我試圖改變indexOf()
與text()
但仍然無法正常工作。
這裏是二值編碼,我試過,但我失敗了
// when the document is ready
$(document).ready(function() {
// iterate over all the anchor tags
$("a").each(function() {
// if the current link's href doesn't already contain 'www.kownleg.com'
if (this.href.indexOf('www.kownleg.com') === -1) {
// change current link to home page
this.href = 'http://www.kownleg.com';
}
if (this.href.indexOf('www.facebook.com') === -1) {
// change current link to home page
this.href = 'http://www.facebook.com';
}
if (this.href.indexOf('www.twitter.com') === -1) {
// change current link to home page
this.href = 'http://www.twitter.com';
}
});
});
另一個問題:
// when the document is ready
$(document).ready(function() {
// iterate over all the anchor tags
$("a").each(function() {
// if the current link's href doesn't already contain 'www.kownleg.com'
if (this.href.indexOf('www.kownleg.com') === -1) {
// change current link to home page
this.href = 'http://www.kownleg.com';
}
if (this.href.text('www.facebook.com') === -1) {
// change current link to home page
this.href = 'http://www.facebook.com';
}
if (this.href.text('www.twitter.com') === -1) {
// change current link to home page
this.href = 'http://www.twitter.com';
}
});
});
和所有的類似的可能性......但仍然沒有爲我工作。
不工作.. :( – 2013-03-16 18:54:35