Phonegap:点击外部网站中的后退按钮后打开应用程序(package.html) [英] Phonegap:Open app(package.html) after clicking upon back button in an external site

查看:77
本文介绍了Phonegap:点击外部网站中的后退按钮后打开应用程序(package.html)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How can i navigate back to a page in my android app after loading an external site. 

1.Open app 

2.In app user will go to an external link 

3.External site has link,which take the user back to app. 

How can i go to my application . I have tried to give "file:///android_asset/www/package.html" in href but its not working at all . Please suggest me and thank you in advance.

推荐答案

你需要实现一个自定义URL方案



然后你会嵌入一个链接,其中包含一个独特的方案应用程序如:



myappname:// information / to / be / pass / back



您的应用程序安装清单告诉操作系统您的应用程序想要接受哪些URL方案。操作系统然后开始监听您并自动加载您的应用程序,在点击/点击适当的URL时传递完整的URL。



浏览器例如没有'注册自定义方案。它注册 http https 。当你点击电子邮件等内容中的标准网页链接时,操作系统就知道如何选择浏览器



这两个过程类似Android和iOS,幸运的是有一个标准化API的插件,简化了PhoneGap / Cordova的这个过程。



EddyVerbruggen / Custom-URL-scheme·GitHub [ ^ ]



在旁注 - 您永远不应将外部托管的Web内容直接加载到Cordova WebView中。在iOS上,这可能会导致您的申请被拒绝。



将外部网页加载到您的应用程序中Cordova WebView使该页面可以完全访问该设备(在该范围内)应用程序权限)。



如果您需要加载外部托管的网页,您应该退出到系统浏览器或适当时使用PhoneGap InAppBrowser。



InAppBrowser - Apache Cordova [ ^ ]



或者,如果您只是想从服务器获取内容以嵌入您的应用程序,那么我只是使用AJAX来获取内容和javascript来管理视图更新。这样,您就可以捕获失败的请求,而不会导致应用程序因用户可能无法恢复的500,404或其他标准HTTP响应错误而崩溃。
You need to implement a custom URL scheme.

You'd then embed a link with a scheme which is unique to your app such as:

myappname://information/to/be/passed/back

When your application installs the manifest tells the operating system which URL schemes your application wants to accept. The OS then starts listening for you and automatically loads your applications, passing in the full URL, when an appropriate URL is clicked/tapped.

A browser for example doesn't register a custom scheme. It registers http and https. This is how the operating system knows to give you a choice of browser when you click standard web links in content such as e-mail e.t.c.

This process is similar on both Android and iOS and luckily there's a plugin which standardises the API and simplifies this process for PhoneGap/Cordova.

EddyVerbruggen/Custom-URL-scheme · GitHub[^]

On a side note - You should never load externally hosted web content directly into the Cordova WebView. On iOS this is likely to get your application submission rejected.

Loading external webpages into your applications Cordova WebView gives that page full access to the device (Within the scope of the applications permissions).

If you need to load an externally hosted web pages you should exit to the system browser or if appropriate use the PhoneGap InAppBrowser.

InAppBrowser - Apache Cordova[^]

Alternatively if you're just looking to get content from the server to embed in your application then I'd just use AJAX to get the content and javascript to manage the view update. This gives you the benefit of being able to catch failed requests without your application crashing out with a 500, 404 or some other standard HTTP response error from which your user may not be able to recover from.


这篇关于Phonegap:点击外部网站中的后退按钮后打开应用程序(package.html)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆