发送多个应用程序协议请求(类似于mailto:) [英] Send multiple application protocols requests ( Similar to mailto: )

查看:146
本文介绍了发送多个应用程序协议请求(类似于mailto:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用创建自己的协议的应用程序,如MS为其MSN客户端 msnim:chat?contact = test@test.com



但是,我需要创建一个PHP或JavaScript(或组合)来基本上尽可能快地向协议发送3个请求。我还希望如果最终结果是 www.test.com/send.php ,用户链接< a href ='www.test .com / send.php'> 不会弹出或重定向到页面,非常像

< ;?php header('Location:msnim:chat?contact = test@test.com'); ?> 不会在用户点击href时创建新页面或重定向

这是我的概念验证的JQUERY和JSBin



http://jsbin.com/etubas/11/

  $(document).ready(function(){
$(a#click_me)。click(function (){
setTimeout(function(){
console.log('test ran');
window.location ='mailto:test@test.com';
} ,100);
setTimeout(function(){
console.log('new ran');
window.location ='mailto:new@new.com';
},200);
});
});

这对IE9来说似乎可以正常工作,并且我可以看到IE8。编辑1:使用MSN更新而不是AIM链接,以便更通用地进行测试,并且包含jquery示例和JSbin

编辑2:更新为mailto链接

解决方案

以下HTML / JavaScript代码将观察对< a id =click_me> 的点击并创建两个新的iFrame到一个可触发您创建的自定义URI方案的URL:

 < html> 
< head>
< script type =text / javascript>
$(document).ready(function(){

var imURL ='http://josh.gitlin.name/9472703.php?id='; //将其更改为你的URL

函数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>一些内容< / p>
< p>< a href =#id =click_me>点击我!< / a>< / p>
< div id =imLinks>< / div>
< / body>
< / html>

以下PHP代码将显示在内部iFrames:

 <?php 

$ screenname ='';
$ b $ switch($ _ REQUEST ['id']){
case'1':$ screenname ='firstPerson';打破;
案例'2':$ screenname ='secondPerson';打破;
默认值:$ screenname ='otherPerson';打破;
}

echo< < html>
< head>
< meta http-equiv =refreshcontent =0; url = aim:goim?screenname = $ screenname>
< / head>
< / html>
END_OF_HTML;

在Safari下测试和Chrome ,当链接被点击时,这会打开多个IM窗口。显然是调整到你的满意。


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 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:chat?contact=test@test.com'); ?> 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:test@test.com';
        }, 100);
        setTimeout(function(){
            console.log('new ran');
            window.location = 'mailto:new@new.com';
        }, 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.

这篇关于发送多个应用程序协议请求(类似于mailto:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆