【发布时间】:2016-05-25 09:55:46
【问题描述】:
有没有办法检测内容是由独立的 Chrome 还是在 web 视图中(来自 chrome 应用程序)访问的?例如
if(chromeapp) {
//content is in a webview / chromeapp
} else {
//all other browsers
}
也可以是 jQuery...
编辑:我正在开发一个连接到内容管理网站的 chrome 应用程序。在全局 js 文件中,我需要根据访问的位置返回不同的值。
如果桌面返回这个... 如果iOS返回这个...... 如果安卓等... 如果 chrome 应用程序...
这是一个将内容嵌入为<webview>的打包应用。
{
"manifest_version": 2,
"name": "...",
"short_name": "...",
"description": "...",
"version": "...",
"minimum_chrome_version": "38",
"default_locale": "en",
"icons": {
"16": "...",
"128": "...",
"192": "...",
"256": "...",
"384": "...",
"512": "..."
},
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [
"<all_urls>",
"storage",
"system.memory",
"system.network",
"unlimitedStorage",
{"fileSystem": ["write", "retainEntries", "directory"]},
"webview",
"downloads",
"fullscreen"
],
"webview" : {
"partitions": [{
"name" : "trusted*",
"accessible_resources": ["<all_urls>"]
}]
},
"sockets": {
"tcpServer" : {
"listen": ["*"]
}
}
}
【问题讨论】:
-
你能更好地解释你的场景吗?托管应用程序?嵌入在
<webview>?该应用程序在您的控制之下吗?您说“Chrome 应用程序”是指“Chrome 浏览器”吗?为什么需要这个? -
@Xan 对不起。见编辑。
-
那么你有什么样的应用程序?该网站的hosted app?还是以某种方式共享 JavaScript 的 packaged app?还是嵌入网站as
<webview>的打包应用程序?还是Progressive Web App?也许如果您添加应用清单会有所帮助。 -
问题已更新。请原谅我,但我不确定这个问题有什么令人困惑的地方:导航器是 chrome 还是 chrome 应用程序中的 chrome?
-
令人困惑的部分是“在 chrome 应用程序中”可能意味着大约 5 种不同的东西。现在问题很清楚了(“在
<webview>标签内”)。
标签: javascript jquery google-chrome-app browser-detection