hide url at status bar

烂漫一生 提交于 2019-11-29 16:33:03

问题


I've read that people have asked this question many times and I have found an answer for it, although I had to do it manually for ALL links in my blog. But I'm stumbled with the format that I can't get to work:

the format I use:

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

but I can't get it to work for data:post.href, it won't open at all.

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

Can anyone please help me with this? Thanks in advance


回答1:


In general, not having a href link in the is not recommended for SEO reasons. Google's crawler relies on the the href in the links to crawl the site, and link juice passes on using the href in the tag. For your site to rank better in the search results, you will need to href to supply the tree structure for GoogleBot.

To prevent copying I suggest you use a little of jQuery to hide the href tags. It utilises javascript to remove the href tags. On click of the links, it will open a new window with the href location.

Example is provided below:

<!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>



回答2:


I'm not sure what exactly you get from data:post.href! just try to use return false after url like below :

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


来源:https://stackoverflow.com/questions/27716122/hide-url-at-status-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!