在状态栏隐藏网址

问题描述 投票:0回答:3

我读到人们多次问过这个问题,并且我已经找到了答案,尽管我必须手动为博客中的所有链接执行此操作。但我被我无法开始工作的格式迷惑了:

我使用的格式:

<a onclick='location.href="#"' style='cursor: pointer;'target='_blank'>

但我无法让它用于 data:post.href,它根本无法打开。

<a onclick='location.href="data:post.href"' style='cursor: pointer;' target='_blank'>

有人可以帮我解决这个问题吗?预先感谢

javascript onclick blogs
3个回答
4
投票

一般来说,出于 SEO 的原因,不建议在 中没有 href 链接。 Google 的抓取工具依靠链接中的 href 来抓取网站,并且链接汁使用标记中的 href 进行传递。为了使您的网站在搜索结果中排名更高,您需要使用 href 来为 GoogleBot 提供树结构。

为了防止复制,我建议您使用一些 jQuery 来隐藏 href 标签。它利用 javascript 删除 href 标签。单击链接时,它将打开一个包含 href 位置的新窗口。

示例如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
    <script>
        $(function(){
            $("a.hidelink").each(function (index, element){
                var href = $(this).attr("href");
                $(this).attr("hiddenhref", href);
                $(this).removeAttr("href");
            });
            $("a.hidelink").click(function(){
                url = $(this).attr("hiddenhref");
                window.open(url, '_blank');
            })
        });
    </script>
    <style>
        a.hidelink {
            cursor: pointer;
            text-decoration: underline;
        }
    </style>
</head>
<body>
<a class="hidelink" href="http://www.google.com">Some Link</a>
</body>
</html>

0
投票

我不确定您从 data:post.href 中到底得到了什么!只是尝试使用 在网址后返回 false,如下所示:

<a onclick='location.href="data:post.href";return false;' style='cursor: pointer;' target='_blank'>

0
投票

好的脚本@maskie,但是它不适用于任何浏览器。当您使用 Dremaviwer 离线测试时它可以工作,但是当在托管中上传时,没有任何反应。

© www.soinside.com 2019 - 2024. All rights reserved.