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
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.
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) $("", {src:s, class:"mailto-iframe"}).appendTo("body");
}
It checks that the url is passed from a non-empty attribute, dynamically creates an iframe element and maps attributes to it and "runs" it by appending to body.
Completed here: http://jsfiddle.net/uaLVh/ - extra bonuses include some css to hide helper iframes and to style protocol-specific links. And yes, I know I promised to iterate over href attribures but I've just done it manually.
html
Don't click me
Click me!
css
/*prevent these iframes from being visible*/
iframe.mailto-iframe{display:none;}
/*bonus: style your protocol-specific links*/
a[href^="mailto:"] {padding-left:20px;background:url(http://sstatic.net/stackoverflow/img/favicon.ico) no-repeat;}
js
$('a[href^="mailto:"]').bind("click", function(e){
//cache "this" link element jquery reference
$this=$(this);
//remove "helper" iframes if any, you don't want to end up with 300 iframes by accident!
$("iframe.mailto-iframe").remove();
//go wild... you could have a nice loop as you're not limited to 3 hrefs
openMailto($this.attr("href"));
openMailto($this.attr("href2"));
openMailto($this.attr("href3"));
//processing href2 and href3 before allowing the default action to happen firstseemed counter-intuitive
e.preventDefault();
return false;
});
function openMailto(s){
if (s) $("", {src:s, class:"mailto-iframe"}).appendTo("body");
}