phonegap:打开外部页面,然后回到应用程序 [英] phonegap: open external page and then go back to app

查看:320
本文介绍了phonegap:打开外部页面,然后回到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定,浏览我已经找到正确的方式加载外部页面到phonegap视图(即没有失去会话或打开设备浏览器),如下所述的问题:如何在phonegap webview中加载网页?
iPhone的PhoneGap:加载外部网址时遇到问题

ok, browsing the questions I've found the right way to load an external page into the phonegap view (i.e. without loosing the session or opening the device browser) as explained here: How can I load a webpage inside the phonegap webview? and here: PhoneGap for iPhone: problem loading external URL

下一步是:在我打开一个extarnal页面(它由我拥有,我可以修改它)后,我怎么能回到我的本地应用程序?假设我在外部页面有一个链接,我希望用户被重定向回手机gap应用程序内的本地html页面(mypage.html)点击。

Next step is: after i've opened an extarnal page (it's owned by me and I can modify it) how can i go back to my local application? Let's say I have a link in the external page and I want the user to be redirected back to a local html page (mypage.html) inside the phonegap application on click.

链接的href属性应包含哪些网址?我已尝试将其设置为file:///android_asset/www/mypage.html,但无效

What url should the link's href attribute have? I've tried setting it to "file:///android_asset/www/mypage.html" but didn't work

推荐答案

您希望使用 ChildBrowser 插件打开外部网络页。然后,您要将ChildBrowser.onLocationChange属性设置为您自己的函数。然后,当用户离开远程页面时,您将收到位置更改的通知,因此您可以关闭ChildBrowser并导航到新的本地页面。您甚至不需要触摸远程html页面。

You want to use the ChildBrowser plugin to open the external web page. Then you want to set the ChildBrowser.onLocationChange property to your own function. Then when the person navigates away from the remote page you will be notified of the location change so you can then close the ChildBrowser and navigate to a new local page. You won't even need to touch the remote html page.

因此,当用户离开远程页面时关闭浏览器:

So to close the browser when the user navigates away from the remote page:

cb.onLocationChange = function(loc){
    console.log("location = " + loc);
    if (loc != "http://example.com") {
        cb.close();
    }
}; 

这篇关于phonegap:打开外部页面,然后回到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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