1

I encounter a problem with jQuery and anchors which href concerns a microsoft desktop windows application. I am working on an internal app which provides links such as :

<a id="launch-21" class="launch-app" href="c:\windows\explorer.exe" target="_blank">

I would like to target all the link containing windows for instance in order to bind the following actions :

jQuery('a[href*="windows"]').click(function(event){
    alert("use this link in your windows workstation");
    event.preventDefault();
});

This has no absolutly no effect. But when I run the following selector, elements are well returned.

It seems the treatment doesn't work with hard drive links ? jQuery('a[href*="windows"]') Does anybody an help me ?

4

1 回答 1

0

Your code seems to work without any problem,

Maybe you're running it before $(document).ready is triggered, or the links in question are loaded in the DOM and ready to be parsed using javascript.

Try changing your javascript to:

(I've created a fiddle for this, you may test it there)

jQuery(document).ready(function(){
    jQuery('a[href*="windows"]').click(function(event){
        var link = jQuery(this).attr("href");
        window.prompt("use this link in your windows workstation", link);
        event.preventDefault();
    });
});

(please note that i took the liberty of changing your alert to a prompt in order to do some testing)

In alternative you can also move your javascript to the end of the page, before closing your <body> tag.

于 2013-02-18T17:51:47.427 回答