如何对私有/自定义URL协议发出jQuery GET / AJAX请求? [英] How to make a jQuery GET/AJAX request to a private/custom URL protocol?

查看:517
本文介绍了如何对私有/自定义URL协议发出jQuery GET / AJAX请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mac和iOS平台上,可以通过自定义URI方案/ NSURLProtocol 与本机运行时进行双向交换。例如..要从本机Objective-C方法请求 NSImage ,您可以注册自定义处理程序(一个简单的字符串,我在这里使用 mycustomprotocol )使用Webkit /你的 WebView NSView ,然后从JS调用它......

On both Mac and iOS platforms, it is possible to do two-way interchange with the native runtime through custom URI schemes / a NSURLProtocol. For example.. to request an NSImage from a native Objective-C method, you can register your custom handler (a simple string, here i used "mycustomprotocol") with Webkit / your WebView NSView, and call it from JS like…

var theURL = 'mycustomprotocol:///' + (textField.value);
img.innerHTML = '<img src="'+theURL+'" id="string"/>';

我希望能够使用jQuery来发出请求,因为在这一点上,它是比90年代风格的JS更熟悉..但据我在网上找到, $。获得 $。ajax 只能 http(s)

I would LIKE to be able to use jQuery to do make requests, as at this point, it is more familiar than 90's-style JS.. but as far as I can find on the web, $.get and $.ajax only do http(s).

会是什么样的

javascript:document.location = 'mycustomprotocol://'

覆盖jquery的URL处理?当谈到JavaScript时,我很愚蠢,我确信这很容易完成。我相信这就是整个jQuery移动框架的实现方式(通过私有URI)。所以,为什么google上没有任何内容关于它,对吧?我可以从姐姐朋友那里得到一些帮助吗?

override jquery's URL handling? I'm a dumbdumb when it comes to JavaScript, I'm sure this is easily done.. I do believe this is how the entire jQuery mobile framework is implemented (via private URI's).. So, why is there nothing on google or SO about it, huh? Can i get some help from my sister friends?

推荐答案

以下是我为 callto所做的事情: 协议,适用于Firefox 24和IE 10(我没有测试任何其他浏览器):

Here is what I did for a callto: protocol, which works in Firefox 24 and IE 10 (I haven't tested any other browsers):

首先 - 您的协议必须已经是注册或您的计算机将无法识别它。
其次在你的标记中创建一个隐藏的链接,你的协议作为href。
当我点击一个按钮( #calltobutton )时,它会设置隐藏链接的值( #clicker )然后点击它,导致浏览器执行操作。

First - your protocol must already be registered or your computer won't recognize it. Second create a hidden link in your markup with your protocol as the href. When I click on a button (#calltobutton), then it sets the value of the hidden link (#clicker) and then and then clicks it, causing the browser to perform the action.

然后执行此操作:

$('#calltobutton').click(function () {
    initCallTo(1234567890);
});


function initCallTo(callto) {
    $('#clicker').attr('href', "callto:" + callto);
    $('#clicker')[0].click();
}

现在,点击callto链接的方法很奇怪。您可以在这里的帖子

Now, the method of clicking on the callto link is a but strange. You can read more about that in this here thread.

这篇关于如何对私有/自定义URL协议发出jQuery GET / AJAX请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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