Send multiple application protocols requests ( Similar to mailto: )

前端 未结 2 1545
慢半拍i
慢半拍i 2021-02-15 13:16

I work with an application that has created it\'s own protocol such like MS did for its MSN client msnim:chat?contact=test@test.com

However, I need to creat

2条回答
  •  执念已碎
    2021-02-15 13:51

    Update:

    As BHare points out, none of the "multiple popup" approaches seem to work in the latest versions of Chrome. The reason behind that is their detection of "user-initiated" actions as opposed to potentially malicious flooding of user screens with unwanted windows.

    In essence, Chrome would allow you to trigger no more than one pop-up per click event. The click event also has to be unique so it cannot trigger a handler that will show popup #1, propagate to the parent and trigger another handler that will show popup #2 etc.

    Another failed attempt was made by attempting to distribute the popups (main page initiates popup A that initiates popup B that initiates popup C etc.) - this was recognized as a non-user-initiated action and only one protocol call was ultimately allowed.

    It is unfortunate that this behaviour is not controlled by an editable policy, i.e. it cannot be adjusted by allowing popups based on the origin domain.

    Depending on deployment specifics (i.e. intranet vs. internet) you may be able to code an extension for Chrome that would initiate the popups at chrome level (meaning browser chrome, effectively any content/style/script that exists outside and above any individual page). Your page can, in turn, detect custom add-on availability and have your "triple links" channelled through to that extension, or prompt the end-user to have the add-on installed. Seeing how you're unable to modify the behaviour of target protocol links (by, for instance, combining the instructions into a single call similar to that of href="mailto:first@email.com,second@email.com,third@email.com") this may be the only option available to you at this stage.

    Original answer:

    Protocol-specific link would work just as well on the client-side without ever going to the server; you can just add an iframe(s) at runtime with correct src set.

    First, let's take good care of the markup. It's demeaning having to manually assign urls to click functions. I've done it the first way that worked and made sense (at the price of html validation), but you could be neater and use custom data-* attributes:

    Click me!

    You know what else is demeaning? Having to manually bind click functions - it just takes too much effort. And what if there were two anchors like that? Let's just tell jQuery to bind the click event to every link that uses this protocol:

    $('a[href^="mailto:"]').bind("click", function(e){
        /*Do stuff*/
    });
    

    Before we iterate over the href~href3 attributes, let's write a function that will handle opening individual mailto links:

    function openMailto(s){
        if (s) $("