html 打开本地可执行文件
windows设置
#coding=utf-8
import _winreg
path = u'C:\\FFM_FTP\\ffm_ftp.exe'
#必须以管理员身份运行
class createKey():
def __init__(self):
key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "FFM")
key_shell = _winreg.CreateKeyEx(key, 'shell', 0, _winreg.REG_CREATED_NEW_KEY)
key_shell_open = _winreg.CreateKeyEx(key_shell, 'open', 0, _winreg.REG_CREATED_NEW_KEY)
# 创建数值的名称和值
_winreg.SetValueEx(key, 'URL Protocol', 0, _winreg.REG_CREATED_NEW_KEY, u'URL:Go Protocol Handler') # 设置项中:创建数值的名称和值
_winreg.SetValue(key, 'Defaultlcon', _winreg.REG_CREATED_NEW_KEY,
path) # 创建子项并设置键中默认的名称的值
_winreg.SetValue(key_shell_open, 'command', _winreg.REG_CREATED_NEW_KEY,
path + ' FFM://ffm_ftp')
_winreg.FlushKey(key)
_winreg.CloseKey(key)
print 'set path is ok'
regedit = createKey()
linux设置
#encoding: utf-8
import os
from subprocess import call
desktop = '''
[Desktop Entry]
Name=FFM ftp
GenericName=Text Editor
Comment=Handle URL Scheme ffmftp://
Exec=/usr/local/FFM_FTP/ffm_ftp %u
Terminal=false
Type=Application
MimeType=x-scheme-handler/ffmftp;
Icon=sublime-text-2
Categories=TextEditor;Development;Utility;
Name[en_US]=FFM ftp
'''
handler = '''
#!/usr/bin/env bash
request="${1#*://}" # Remove schema from url (ffm_ftp://)
request="${request#*?url=}" # Remove open?url=
request="${request//%2F//}" # Replace %2F with /
request="${request/&line=/:}" # Replace &line= with :
request="${request/&column=/:}" # Replace &column= with :
ffmftp "$request" # Launch sublime
'''
if __name__ == '__main__':
if not os.path.exists('/usr/share/applications'):
os.makedirs('/usr/share/applications/')
if not os.path.exists('/usr/share/handlers'):
os.makedirs('/usr/share/handlers')
with open('/usr/share/applications/ffm_ftp.desktop', 'wb') as f:
f.write(desktop)
with open('/usr/share/handlers/ffm_ftp', 'wb') as f:
f.write(handler)
#call('update-desktop-database')
#call('chmod +x /usr/share/handlers/sublime-handler')
import os
os.system('update-desktop-database')
os.system('chmod +x /usr/share/handlers/ffm_ftp')
# 使用说明
# subl:///home/path/to/file.php:123
# subl://open?url=/home/path/to/file.php:123
# subl://open?url=/home/path/to/file.php&line=123
# subl://open?url=/home/path/to/file.php&column=123
# subl://open?url=%2Fhome%2Fpath%2Fto%2Ffile.php&line=123
# subl://open?url=%2Fhome%2Fpath%2Fto%2Ffile.php&column=123
html 的使用(flask服务器版本)
<!DOCTYPE html>
<html lang="en">
<link href=" {{ url_for('static', filename='res/bootstrap-3.3.7-dist/css/bootstrap.css') }}" rel="stylesheet"/>
<link href=" {{ url_for('static', filename='res/jquery-ui-1.12.1/jquery-ui.css') }}" rel="stylesheet"/>
<link href=" {{ url_for('static', filename='res/bootstrap-3.3.7-dist/css/bootstrap.css') }}" rel="stylesheet"/>
<script src="{{ url_for('static', filename='res/jquery-3.1.1.min.js') }}"></script>
<script src="{{ url_for('static', filename='res/jquery-ui-1.12.1/jquery-ui.min.js') }}"></script>
<script src="{{ url_for('static', filename='res/bootstrap-3.3.7-dist/js/bootstrap.js') }}"></script>
<link href=" {{ url_for('static', filename='css/style.css') }}" rel="stylesheet"/>
<script src="{{ url_for('static', filename='js/test.js') }}"></script>
<img src="{{ url_for('static', filename='images/cat.jpg') }}">
<head>
<meta charset="UTF-8">
<title>this is a html</title>
</head>
<body>
<div>
{% if user %}
<a href="#">{{ user.username }}</a>
<a href="#">注销</a>
{% else %}
<a href="#">登陆</a>
<a href="#">注册</a>
{% endif %}
</div>
<div>
<button type="button" id="myButton" onclick="myFunction()">Basic1</button>
<button type="button" class="btn btn-primary">Basic2</button>
<a href="Gok://sublime">调用sublime</a>
</div>
</body>
</html>
<script>
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (macosPlatforms.indexOf(platform) !== -1) {
os = 'Mac OS';
} else if (iosPlatforms.indexOf(platform) !== -1) {
os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = 'Windows';
} else if (/Android/.test(userAgent)) {
os = 'Android';
} else if (!os && /Linux/.test(platform)) {
os = 'Linux';
}
return os;
}
function myFunction()
{
os = getOS()
if (os == 'Windows')
{
window.location.href = "FFM://ffm_ftp";
}
else if(os == 'Linux')
{
window.location.href = "ffmftp:///home/path/to/file.php:123"
}
console.log('Hello!')
}
</script>
版权声明:本文为BigTail_cat原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。