移动 H5 唤起 APP
URL Schema 是一种用于定位和访问互联网上资源的标准化地址格式。 也可以作为页面内跳转协议,通过这个协议可以比较方便的跳转到 APP、客户端的某页面。
** 协议 (Scheme) **:用于定义访问资源所使用的协议,如 http、https、ftp 等。表示用于访问资源的方法。
一个简单的 Schema 协议格式如下:
**[scheme]://[path]?[query]**
scheme
: 协议名称(由开发人员自定义)(必要,其他都是可选)path
: 页面路径query
: 请求参数
例如,可以这样调用 Schema:
| <a href="myApp://file?type=folder&id=ESC">打开 APP 查看</a>
|
Electron 中的自定义 URL Schema (chatgpt)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| const { app, protocol, BrowserWindow } = require("electron"); const path = require("path");
app.on("ready", () => { protocol.registerFileProtocol("myapp", (request, callback) => { const url = request.url.substr(7); callback({ path: path.normalize(`${__dirname}/${url}`) }); });
const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false, }, });
mainWindow.loadURL("myapp://index.html"); });
|