如何在某些页面中仅显示链接

时间:2015-12-31 19:33:48

标签: html css

除了主页之外,我希望在博客上随处可见链接。

但是我只希望链接在主页上不起作用,我仍然想要单词YOUR PAGE,只是没有链接。

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

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

通过CSS

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

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

相关问题