最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - hide url at status bar - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question edited Dec 31, 2014 at 4:30 Raptor 54.3k47 gold badges248 silver badges399 bronze badges asked Dec 31, 2014 at 4:27 Jaz AbJaz Ab 31 gold badge1 silver badge2 bronze badges 2
  • Please check this link. Might be it helps you. stackoverflow./questions/19256453/… – Lakhan Commented Dec 31, 2014 at 6:20
  • Also try it "window.location.href" in place of "location.href". – Lakhan Commented Dec 31, 2014 at 6:23
Add a ment  | 

2 Answers 2

Reset to default 4

In general, not having a href link in the is not remended 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./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.">Some Link</a>
</body>
</html>

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'>
发布评论

评论列表(0)

  1. 暂无评论