pt吧 关注:222,681贴子:11,644,152
  • 11回复贴,共1

【241230】有没有人好奇浏览器打开过qb的页面之后,就能自动跳转

只看楼主收藏回复

有没有人好奇为什么用浏览器打开过qb的页面之后,再点击magnet:// 链接,会自动打开你刚刚访问的qb页面。
其实本质上利用的是 url scheme协议,一般这种协议是用来打开app的。
qb的源码里有个registerMagnetHandler方法,就是通过这个实现的,用了浏览器registerProtocolHandler的api。
# 注册magnet协议处理方法
function registerMagnetHandler() {
if (typeof navigator.registerProtocolHandler !== 'function') {
if (window.location.protocol !== 'https:')
alert("要使用此功能,WebUI 需要通过 HTTPS 访问");
else
alert("您的浏览器不支持此功能");
return;
}
const hashString = location.hash ? location.hash.replace(/^#/, '') : '';
const hashParams = new URLSearchParams(hashString);
hashParams.set('download', '');
const templateHashString = hashParams.toString().replace('download=', 'download=%s');
const templateUrl = location.origin + location.pathname
+ location.search + '#' + templateHashString;
navigator.registerProtocolHandler('magnet', templateUrl,
'qBittorrent WebUI magnet handler');
}


IP属地:浙江1楼2024-12-30 23:42回复


    IP属地:浙江2楼2024-12-30 23:43
    回复
      2025-09-06 17:09:03
      广告
      不感兴趣
      开通SVIP免广告
      cy


      IP属地:江西来自iPhone客户端3楼2024-12-30 23:56
      回复
        绑定


        IP属地:湖北来自Android客户端4楼2024-12-31 00:43
        回复
          绑定


          IP属地:浙江来自Android客户端5楼2024-12-31 01:15
          回复
            绑定


            IP属地:湖北来自Android客户端6楼2024-12-31 08:41
            回复
              绑定


              IP属地:北京来自iPhone客户端7楼2024-12-31 11:08
              回复


                IP属地:上海来自Android客户端8楼2024-12-31 13:14
                回复
                  2025-09-06 17:03:03
                  广告
                  不感兴趣
                  开通SVIP免广告
                  绑定


                  IP属地:广东来自Android客户端9楼2024-12-31 18:23
                  回复
                    技术贴


                    IP属地:广东13楼2025-01-02 11:15
                    回复
                      cy


                      IP属地:四川来自iPhone客户端14楼2025-01-08 01:07
                      回复
                        绑定。


                        IP属地:山西来自Android客户端15楼2025-01-14 13:03
                        回复