{"id":10969,"date":"2023-08-30T23:02:58","date_gmt":"2023-08-30T15:02:58","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10969"},"modified":"2023-08-30T23:07:45","modified_gmt":"2023-08-30T15:07:45","slug":"js-registerprotocolhandler","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2023\/08\/js-registerprotocolhandler\/","title":{"rendered":"\u4e00\u8a00\u96be\u5c3d\u7684registerProtocolHandler()\u65b9\u6cd5"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10969\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10969<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202308-register-p.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/cat-cover.png\" width=\"480\" height=\"306\" alt=\"\u732b \u65e5 \u5c01\u9762\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u524d\u4e8b\u4e0d\u5fd8\u540e\u4e8b\u4e4b\u5e08<\/h3>\n<p>\u7b2c\u4e00\u773c\u770b\u5230<code>registerProtocolHandler()<\/code>\u65b9\u6cd5\u7684\u65f6\u5019\uff0c\u8bf4\u5b9e\u8bdd\uff0c\u6211\u8fd8\u662f\u633a\u5174\u594b\u7684\u3002<\/p>\n<p>\u8fd9\u53ef\u662f\u4e2a\u6709\u8da3\u7684\u4e1c\u897f\u554a\uff0c\u5c45\u7136\u53ef\u4ee5\u81ea\u5b9a\u4e49\u534f\u8bae\u5730\u5740\uff0c\u5e76\u4e14\u53ef\u4ee5\u50cf\u6b63\u5e38\u94fe\u63a5\u4e00\u6837\u8bbf\u95ee\u3002<\/p>\n<p>\u8bd5\u60f3\u4e0b\uff0c\u6709\u4e2a\u94fe\u63a5\u5730\u5740\u662f\uff1a<\/p>\n<pre>&lt;a href=\"web+zxx:css\"&gt;CSS\u6807\u7b7e&lt;\/a&gt;<\/pre>\n<p>\u70b9\u51fb\u540e\uff0c\u53ef\u4ee5\u81ea\u52a8\u8bbf\u95eeCSS\u6807\u7b7e\u9875\u9762\uff0c\u662f\u4e0d\u662f\u5f88\u5e05\u6c14\uff1f<\/p>\n<p>\u53c8\u662f\u88c5\u903c\u4e8e\u65e0\u5f62\u7684\u4e00\u5927\u5229\u5668\u554a\uff0c\u54c8\u54c8\u54c8\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/zhuangbi-s.png\" width=\"149\" height=\"150\" alt=\"\u88c5\u903c\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u53ef\u662f\uff0c\u5f53\u6211\u6df1\u5165\u4f53\u9a8c\u8fd9\u4e2aAPI\u4e4b\u540e\u2026\u2026\u55ef\u2026\u2026\u600e\u4e48\u8bf4\u5462\u2026\u2026\u5509\uff0c\u53ea\u80fd\u8bf4\u4e00\u8a00\u96be\u5c3d\uff0c\u5177\u4f53\u4ec0\u4e48\u60c5\u51b5\uff0c\u542c\u6211\u6162\u6162\u9053\u6765\u3002<\/p>\n<h3>\u4e8c\u3001\u9e1f\u6765\u8fd8\u8bed\u6cd5\uff0c\u5ba2\u53bb\u66f4\u5b89\u7985<\/h3>\n<p>registerProtocolHandler\u7684\u4f7f\u7528\u5206\u4e3a\u6ce8\u518c\u548c\u4f7f\u7528\u4e24\u90e8\u5206\u3002<\/p>\n<p>\u9996\u5148\u662f\u6ce8\u518c\u3002<\/p>\n<p>\u6240\u6709\u81ea\u5b9a\u4e49\u7684\u534f\u8bae\u5934\uff0c\u4e00\u5b9a\u8981\u662f<code>web+<\/code>\u5f00\u5934\uff0c\u540e\u9762\u81f3\u5c11\u8ddf\u968f\u4e00\u4e2a\u82f1\u6587\u5b57\u6bcd\uff08\u4e0d\u80fd\u6709\u6570\u5b57\uff0c\u5426\u5219\u4f1a<a href=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/2023-08-30_222244.png\" rel=\"noopener\" target=\"_blank\">\u62a5\u9519<\/a>\uff09\u3002<\/p>\n<p>\u5426\u5219\u53ea\u80fd\u4f7f\u7528\u4e0b\u9762\u4e4b\u4e00\u7684\u534f\u8bae\u3002<\/p>\n<ul>\n<li><code>bitcoin<\/code><\/li>\n<li><code>ftp<\/code><\/li>\n<li><code>ftps<\/code><\/li>\n<li><code>geo<\/code><\/li>\n<li><code>im<\/code><\/li>\n<li><code>irc<\/code><\/li>\n<li><code>ircs<\/code><\/li>\n<li><code>magnet<\/code><\/li>\n<li><code>mailto<\/code><\/li>\n<li><code>matrix<\/code><\/li>\n<li><code>mms<\/code><\/li>\n<li><code>news<\/code><\/li>\n<li><code>nntp<\/code><\/li>\n<li><code>openpgp4fpr<\/code><\/li>\n<li><code>sftp<\/code><\/li>\n<li><code>sip<\/code><\/li>\n<li><code>sms<\/code><\/li>\n<li><code>smsto<\/code><\/li>\n<li><code>ssh<\/code><\/li>\n<li><code>tel<\/code><\/li>\n<li><code>urn<\/code><\/li>\n<li><code>webcal<\/code><\/li>\n<li><code>wtai<\/code><\/li>\n<li><code>xmpp<\/code><\/li>\n<\/ul>\n<p>\u800c\u4e0a\u9762\u5f88\u591a\u534f\u8bae\uff0c\u6d4f\u89c8\u5668\u662f\u5185\u7f6e\u539f\u751f\u884c\u4e3a\u7684\uff0c\u4f8b\u5982tel\u3001mailto\u3001ftps\u7b49\uff0c\u770b\u8d77\u6765\u662f\u4e0d\u80fd\u968f\u4fbf\u5b9a\u4e49\u7684\uff0c\u5426\u5219\u6709\u53ef\u80fd\u4f1a\u51b2\u7a81\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5148\u4f7f\u7528\u5b8c\u5168\u81ea\u5b9a\u4e49\u7684\u534f\u8bae\u770b\u770b\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b\uff08\u6ce8\u610f\uff0c\u540e\u9762\u7684\u5730\u5740\u4e0d\u80fd\u8de8\u57df\uff0c\u5426\u5219\u4e5f\u4f1a<a href=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/2023-08-30_221952.png\" rel=\"noopener\" target=\"_blank\">\u62a5\u9519<\/a>\uff09\uff1a<\/p>\n<pre>navigator.registerProtocolHandler('web+zxx', 'https:\/\/www.zhangxinxu.com\/wordpress?s=%s');<\/pre>\n<p>\u6211\u4e00\u5f00\u59cb\u4ee5\u4e3a\u662f\u8fd9\u6837\u7684\uff0c<code>%s<\/code>\u8868\u793a\u4f7f\u7528\u65f6\u5019\u534f\u8bae\u5192\u53f7\u540e\u9762\u7684\u53d8\u91cf\uff0c\u6240\u4ee5\u5982\u679c\u6709\u94fe\u63a5\uff1a<\/p>\n<pre>&lt;a href=\"web+zxx:css\"&gt;CSS\u6807\u7b7e&lt;\/a&gt;<\/pre>\n<p>\u70b9\u51fb\u540e\uff0c\u8bbf\u95ee\u7684URL\u662f https:\/\/www.zhangxinxu.com\/wordpress?s=css\u3002<\/p>\n<p>\u7136\u800c\uff0c\u771f\u6b63\u8fd0\u884c\u540e\uff0c\u5927\u8dcc\u773c\u955c\u3002<\/p>\n<p>\u9996\u5148\u662f\u6743\u9650\u63d0\u793a\uff0c\u9009\u62e9\u5141\u8bb8\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/2023-08-30_220523.png\" width=\"411\" height=\"214\" alt=\"\u5141\u8bb8\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5728Windows Chrome\u4e0b\uff0c\u8fd8\u4f1a\u547c\u8d77\u7cfb\u7edf\u7a97\u53e3\uff0c\u8ba9\u4f60\u9009\u62e9\u547c\u8d77\u7684\u672c\u5730\u8f6f\u4ef6\u3002<\/p>\n<p>Firefox\u6d4f\u89c8\u5668\u5219\u662f\u81ea\u5e26\u7684\u63d0\u793a\uff0c\u9009\u62e9\u201c\u9009\u62e9\u5e94\u7528\u7a0b\u5e8f\u201d\u540e\uff0c\u518d\u9009\u62e9\u6700\u4e0a\u9762\u7684\u5f53\u524d\u57df\u540d\u7684\u8fd9\u4e2a\u9009\u9879\u5373\u53ef\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/2023-08-30_222555.png\" width=\"481\" height=\"203\" alt=\"Firefox\u4e0b\u7684\u63d0\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6b64\u65f6\uff0c\u5047\u8bbe\u9875\u9762\u4e2d\u6709\u4e2a\u94fe\u63a5\u5143\u7d20\u7684href\u7684\u5c5e\u6027\u503c\u662fweb+zxx:css\u3002<\/p>\n<p>\u5219\u70b9\u51fb\u540e\u6d4f\u89c8\u5668\u7684\u8c03\u6574\u5730\u5740\u662f\u2026\u2026\u8fd9\u4e2a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/2023-08-30_222634.png\" width=\"654\" height=\"357\" alt=\"\u641c\u7d22\u5730\u5740\u6f14\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5b8c\u5168\u8d85\u51fa\u9884\u671f\uff0c<code>%s<\/code>\u6307\u4ee3\u7684\u5c45\u7136\u662f\u5b8c\u6574\u7684href\u5c5e\u6027\u503c\uff0c\u800c\u4e0d\u662f\u534f\u8bae\u540e\u9762\u7684\u503c\u3002<\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u5927\u5bb6\u4e5f\u53ef\u4ee5\u6765\u4f53\u9a8c\u4f53\u9a8c\uff0c\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202308\/js-registerprotocolhandler-demo.php\" rel=\"noopener\" target=\"_blank\">registerProtocolHandler\u6ce8\u518c\u4f7f\u7528\u793a\u610fdemo<\/a><\/p>\n<p>\u8fd9\u5c31\u5bfc\u81f4\uff0cregisterProtocolHandler\u8981\u60f3\u5e94\u7528\uff0c\u4e00\u5b9a\u8981\u5bf9\u52a8\u6001\u6570\u636e\u8fdb\u884c\u989d\u5916\u7684\u5904\u7406\u3002<\/p>\n<p>\u4f8b\u5982\u5bf9URL\u4e2d\u7684\u67e5\u8be2\u5173\u952e\u5b57\u8fdb\u884c\u5b57\u7b26\u5904\u7406\uff0c\u5f97\u5230\u5192\u53f7\u540e\u9762\u7684&#8217;css&#8217;\u5173\u952e\u5b57\u3002<\/p>\n<pre>new URLSearchParams(location.search).get('s').replace('web+zxx:', '');<\/pre>\n<p>\u8fd9\u53ef\u5c31\u9ebb\u70e6\u4e86\u5440\uff0c\u770b\u6765\u8fd9\u73a9\u610f\uff0c\u53ea\u80fd\u7528\u5728\u547c\u8d77\u672c\u5730\u7a0b\u5e8f\u4e0a\uff0c\u76f4\u63a5\u5728Web\u4e0a\u88c5\u903c\u800d\u5e05\u5b8c\u5168\u4e0d\u53ef\u884c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/sign.webp\" width=\"100\" height=\"101\" alt=\"\u53f9\u6c14\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e00\u4e2a\u5b57\uff0c\u5931\u8d25\uff01<\/p>\n<h3>\u4e09\u3001\u5929\u6cb3\u6e10\u5206\u6653\uff0c\u7ed3\u8bed\u95ee\u725b\u90ce<\/h3>\n<p>\u4f24\u5fc3\u6b32\u7edd\uff0c\u5185\u7f6e\u7684scheme\u7c7b\u578b\u6211\u4e5f\u61d2\u5f97\u6d4b\u8bd5\u4e86\uff0c\u4f30\u8ba1\u4e5f\u662f\u4e00\u4e2a\u5c3f\u6027\u3002<\/p>\n<p>\u603b\u800c\u8a00\u4e4b\uff0c\u8a00\u800c\u603b\u4e4b\uff0cregisterProtocolHandler()\u65b9\u6cd5\u60f3\u8981\u5728\u7eafWeb\u4e2d\u73a9\u800d\u662f\u975e\u5e38\u4e0d\u65b9\u4fbf\u7684\uff0c\u4e5f\u662f\u6ca1\u6709\u4efb\u4f55\u610f\u4e49\u7684\u3002<\/p>\n<p>\u975e\u8981\u548c\u672c\u5730\u7684\u5e94\u7528\u7a0b\u5e8f\u7ed3\u5408\u8d77\u6765\u4f7f\u7528\u624d\u6709\u4ef7\u503c\u3002<\/p>\n<p>\u7531\u6b64\u53ef\u89c1\uff0cregisterProtocolHandler()\u65b9\u6cd5\u5c31\u662f\u4e2a\u9e21\u808b\u65b9\u6cd5\uff0c\u6211\u4f30\u8ba1\u6211\u8fd9\u8f88\u5b50\u90fd\u6ca1\u673a\u4f1a\u4f7f\u7528\u4e86\u3002<\/p>\n<p>\u4e5f\u4e0d\u77e5\u9053\uff0c\u4e00\u4e2aURL\u547c\u8d77vscode\u6216\u8005github\u684c\u9762\u7aef\u8f6f\u4ef6\u662f\u4e0d\u662f\u57fa\u4e8e\u6b64\u65b9\u6cd5\u5b9e\u73b0\u7684\u3002<\/p>\n<p>\u55ef\uff0c\u6211\u56de\u60f3\u4e86\u4e0b\u6211\u4e4b\u524d\u5b66\u5230\u7684\u77e5\u8bc6\u2026\u2026\u5e94\u8be5\u4e0d\u662f\uff0c\u5e94\u8be5\u662f\u8fd9\u4e9b\u8f6f\u4ef6\u5728\u5b89\u88c5\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u5728\u7cfb\u7edf\u5185\u6ce8\u518c\u597d\u4e86\u7684\u3002<\/p>\n<p>\u8def\u5f84\u662f\uff0c\u684c\u9762\u8f6f\u4ef6\u6ce8\u518c\uff0c\u6d4f\u89c8\u5668URL\u547c\u8d77\u3002<\/p>\n<p>\u800cregisterProtocolHandler()\u65b9\u6cd5\u662f\u6d4f\u89c8\u5668\u6ce8\u518c\uff0c\u6d4f\u89c8\u5668\u547c\u8d77\u3002<\/p>\n<p>\u8fd9\u4e48\u4e00\u770b\uff0cregisterProtocolHandler()\u65b9\u6cd5\u66f4\u662f\u6ce8\u5b9a\u4e86\u65e0\u4eba\u95ee\u6d25\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u767d\u5f00\u5fc3\u4e00\u573a\uff0c\u4e0b\u7bc7\u6587\u7ae0\u518d\u89c1\u5427\u3002<\/p>\n<p>? ? ? ? ? ? ?<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10969\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10969<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202308\/cat-cover.png\" width=\"160\" height=\"102\" alt=\"\u732b \u65e5 \u5c01\u9762\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u4e00\u5f00\u59cb\u770b\u5230registerProtocolHandler()\u65b9\u6cd5\u8001\u6fc0\u52a8\u4e86\uff0c\u4ee5\u4e3a\u53c8\u53d1\u73b0\u4e86\u4e2a\u597d\u73a9\u5177\uff0c\u8c01\u77e5\u6df1\u5165\u4f53\u9a8c\u4e86\u4e00\u756a\u4e4b\u540e\u2026\u2026\u5475\u5475~<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[215,778,1500,877,1372,1368,1943,1472],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10969"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=10969"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10969\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}