use*_*044 13 javascript angularjs cordova
我正在开发一个应用程序,除了自定义URL方案插件(https://github.com/EddyVerbruggen/Custom-URL-scheme)之外,几乎所有内容都已找到.我已成功安装插件并设置了signsrestaurantandbar的自定义URL方案.所以当我使用signsrestaurantandbar://时,我的应用程序就会打开.我面临的问题是处理URL.在自述文件中,它说我可以使用函数handleOpenURL(URL),但是我仍然在尝试加载应用程序中的特定页面时遇到问题.
这是我试过的:
function handleOpenURL(url) {
var strValue = url;
strValue = strValue.replace('signsrestaurantandbar://','');
window.location.href = strValue + ".html";
}
Run Code Online (Sandbox Code Playgroud)
我把它放在我的index.html页面中......虽然它应该在加载signsrestaurantandbar://页面时打开page.html,但它没有正确执行.在我的chrome控制台中,它表示它已加载页面,但它显示为空白而没有任何错误,这只发生一次.当我第二次尝试加载signsrestaurantandbar://页面时,它只是加载应用程序.
我将不胜感激任何有关如何使用自定义URL方案加载特定页面的提示.
Jes*_*650 11
您需要确保在自己的网站上列出"自定义"网址CSP.
添加2016-02-11:注意:您的应用程序现在已经不安全.由您来保护您的APP.
它看起来像这样:
<meta http-equiv="Content-Security-Policy"
content="default-src * signsrestaurantandbar:;
style-src * 'self' 'unsafe-inline' 'unsafe-eval';
script-src * 'self' 'unsafe-inline' 'unsafe-eval';">
Run Code Online (Sandbox Code Playgroud)
通常,通配符设置(*)可以处理大多数应用程序,但不能处理"自定义"协议.
注意:通配符设置有可能使您的应用程序远离"应用商店".
您可能还需要添加到您的 config.xml
<allow-intent href="signsrestaurantandbar:" />
Run Code Online (Sandbox Code Playgroud)
这个白名单工作表应该有所帮助. 如何应用Cordova/Phonegap白名单系统
您还应该阅读白名单矩阵,尤其是<allow-intent (...) />最佳运气部分
使用以下代码添加全局handleOpenURL函数:
window.handleOpenURL = function(url) {
console.log(">>>>>>>>>>>>>>>>>>>");
// do stuff, for example
// document.getElementById("url").value = url;
console.log(url);
};
Run Code Online (Sandbox Code Playgroud)
请注意,如果您alert在此功能中使用,您的应用会挂起:
您无法在handleOpenURL代码中启动任何交互式功能,如警报,如果您这样做,您的应用将会挂起.类似地,您不应该在那里调用任何Cordova API,除非您首先在setTimeout调用中将其包装,超时值为零.
此方法的好处是您无需使用Content-Security-Policy元标记更改内容安全策略.
| 归档时间: |
|
| 查看次数: |
15441 次 |
| 最近记录: |