最近要現實一個在PC網頁中實現點擊按鈕調用本地應用程序的功能
其實實現原理也非常簡單,
首先注冊一個本地注冊表文件,指向本地應用程序路徑
其次在網頁中用js指向這個注冊表文件,就可以實現網頁調用本地應用程序
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\myprotocol] @="myprotocol Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\myprotocol\DefaultIcon] @="D:\\Tools\\FF\\tencent\\qqmusic\\QQMusic.exe" [HKEY_CLASSES_ROOT\myprotocol\shell] @="" [HKEY_CLASSES_ROOT\myprotocol\shell\open] @="" [HKEY_CLASSES_ROOT\myprotocol\shell\open\command] @="\"D:\\Tools\\FF\\tencent\\qqmusic\\QQMusic.exe\" "
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body style="text-align: center;padding-top: 300px;"> <button onclick="window.location.href='myprotocol://D:\\work\\data\\2018\\08-11\\11-16\\myprotocol.reg'" style="margin: 200px auto;">打開QQ音樂</button> <a href="myprotocol://D:\work\data\2018\08-11\11-16\myprotocol.reg" style="margin: 200px auto;">打開QQ音樂</a> </body> </html>