I work with an application that has created it's own protocol such like MS did for its MSN client msnim:[email protected]
However, I need to create a PHP or javascript (or combo) to basically send 3 requests to the protocol as soon as possible. I also want it if the end result is www.test.com/send.php
that a user link <a href='www.test.com/send.php'>
would not pop up or redirect to a page much like doing
<?php header('Location: msnim:[email protected]'); ?>
would not create a new page or redirect upon user click of href
Here is a JQUERY and JSBin of my proof of concept
http://jsbin.com/etubas/11/
$(document).ready(function(){
$("a#click_me").click(function(){
setTimeout(function(){
console.log('test ran');
window.location = 'mailto:[email protected]';
}, 100);
setTimeout(function(){
console.log('new ran');
window.location = 'mailto:[email protected]';
}, 200);
});
});
This seems to work OK with IE9 and as far as I can see IE8. Firefox 10 seems be OK too but chrome 17 only does 1st email.
Edit 1: Updated with MSN instead of AIM links to be more universal for testing, and include jquery example and JSbin
Edit 2: Updated to mailto links
The following HTML/JavaScript code will observe clicks on <a id="click_me">
and create two new iFrames to a URL which can trigger the custom URI scheme you created:
<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
var imURL = 'http://josh.gitlin.name/9472703.php?id='; // Change this to your URL
function openIM(who) {
var iFrame = '<iframe src="'+imURL+who+'"></iframe>';
$('div#imLinks').append(iFrame);
}
$("a#click_me").click(function(e){
e.preventDefault();
setTimeout(function(){
openIM('1');
}, 100);
setTimeout(function(){
openIM('2');
}, 200);
});
});
</script>
</head>
<body>
<p>Some content here</p>
<p><a href="#" id="click_me">Click Me!</a></p>
<div id="imLinks"></div>
</body>
</html>
The following PHP code is what will be displayed inside those iFrames:
<?php
$screenname = '';
switch($_REQUEST['id']) {
case '1': $screenname = 'firstPerson'; break;
case '2': $screenname = 'secondPerson'; break;
default: $screenname = 'otherPerson'; break;
}
echo <<<END_OF_HTML
<html>
<head>
<meta http-equiv="refresh" content="0;url=aim:goim?screenname=$screenname">
</head>
</html>
END_OF_HTML;
Tested under Safari and Chrome, this will open up multiple IM windows when the link is clicked. Obviously tweak to your satisfaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With