Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send multiple application protocols requests ( Similar to mailto: )

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

like image 908
ParoX Avatar asked Feb 27 '12 21:02

ParoX


1 Answers

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.

like image 97
Josh Avatar answered Sep 25 '22 04:09

Josh