简体   繁体   中英

How can i hide the image path on hover using javascript or jquery

Any one who know the answer please give me the suggestion to do this. I am using mozilla firefox browser, When i hover the image i get the url path of where it is located(left bottom of the mozilla) Here is the screenshot: 在此输入图像描述

Is it possible to hide the href path. Any suggestion would be great.

Assuming that the status bar shows the href destination, you can remove the href attributes onload and call window.location onclick instead: (jQuery):

$(function() {
    $('a[href]').each(function() {
        var href = this.href;
        $(this).removeAttr('href').css('cursor','pointer').click(function() {
            window.location = href;
        });
    });
});

Note that I added cursor:pointer to make it behave like a link even without the href attribute. The very same technique is often used on mobile web sites to prevent mobile safari to drop down it's address bar when navigating through ajax.

Another more clumsy way would be to add a placeholder div on top of the anchor that grabs the anchor's href and navigates using window.location onclick.

Either way, a quick look in the source or in a console would reveal the destination anyway.

I think if you remove href attribute, and add onClick = "location('your url')" it will hide the href path. for example:

<script>
function changeLocation(url){
   window.location.assign(url);
}
</script>
<a onClick = "changeLocation('http://www.w3schools.com')">Link</a>

You can do it by calling on click method that opens image url in browser (url stored in data-href instead of href ):

http://jsfiddle.net/mattydsw/TYSnB/

<a data-href="http://somewhere.com">new</a>

$('a[data-href]').on('click', function(e) {
    e.preventDefault();
    window.location.href = $(this).data('href');
});

EDIT

But also whole rest of "standard" behavior will be lost, eg open in new tab, copy link, search engines crawling.

I see that you have got already one answer for that, but if you want to open in new popup/window on click then it's fine but if you want to open in same page then what happen? also if you have use master page and on click of link like this new page load on content place holder area than what happen?

I have one of solution if you like.

We can use system.webrouting.routecollection in global.asax page for hide all or any page, See below example:

void Application_Start(object sender, EventArgs e)
    {      
        RegisterRoutes(System.Web.Routing.RouteTable.Routes);
    }

void RegisterRoutes(System.Web.Routing.RouteCollection routes)
    {
        routes.Clear();
        routes.MapPageRoute("page1", "dir1/{country}/{State}", "~/page1.aspx");
}

It would be helpful to you.

<a onclick="window.open('http://whatever', '_self');"><img bla bla bla ></a>

编辑:请注意,它可能不适合参考,因为这不是一种自然的链接方式,机器人不会抓取它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM