2015-12-31 42 views
-1

我想要一个链接出现在除首页以外的博客上。如何在某些页面中显示链接

但是,我只希望链接不能在主页上工作,我仍然希望单词YOUR PAGE那里,没有链接。

<center> 
    <div id='customheader'> 
     <a href='http://www.yourpage.com/'>YOUR PAGE</a> 
    </div> 
</center> 
+0

您正在使用的服务器端应用程序是什么?您需要使用脚本语言。无论是在浏览器(JavaScript)上还是在服务器上。 – undefined

+2

[jQuery是否可以检测特定的URL并执行基于该URL的函数?](http://stackoverflow.com/questions/4619601/can-jquery-detect-a-specific-url-and-perform- a-function-based-off-that-url) –

+1

已经在stackoverflow上得到了很多答案,中心标签也被折旧了。 –

回答

1

使用Javascript:

if (document.URL == 'http://www.yourpage.com/') { 
    document.getElementById('customheader').insertAdjacentHTML('afterbegin', 'Your page'); 
} else { 
    document.getElementById('customheader').insertAdjacentHTML('afterbegin', '<a href="http://www.yourpage.com">Your page</a>'); 
} 

使用PHP:

<div id='customheader'> 
<?php 
    if ($_SERVER['REQUEST_URI'] == '/' || $_SERVER['REQUEST_URI'] == "/index.php") { 
    echo "YOUR PAGE"; 
    } else { 
    echo "<a href='http://www.yourpage.com/'>YOUR PAGE</a>"; 
    } 
?> 
</div> 
0

通过CSS

<style type="text/css"> 
    body #customheader a[href]:after { content: ''; } 
</style> 

但你需要让这个只出现在主页。它也不适用于旧版浏览器。

相关问题