如何将参数传递到PhoneGap应用程序中的本地页面? [英] How can I pass parameters to a local page in PhoneGap app?

查看:82
本文介绍了如何将参数传递到PhoneGap应用程序中的本地页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PhoneGap应用中,我们可以使用以下代码设置起始页。

  self.viewController.wwwFolderName = @ 万维网; 
self.viewController.startPage = @index.html;

但是如果我要传递参数到该页面,它将不起作用。

  self.viewController.startPage = @index.html?parameter = abc; 

这将导致 NSURLErrorRedirectToNonExistentLocation 错误。 / p>

有一个简单的方法可以将参数传递到本地页面。

解决方案

p>在phonegap应用程序中,您不能通过向其传递参数来调用本地页面,因为系统将搜索与您传递完全相同的名称的文件。

 例如:当你说index.html?param = abc时,而不是使用名为param的值为abc的
参数调用页面index.html。它调用在系统中不存在的页面index.html?param = abc
。因此,错误。

解决问题的最佳方法是将参数作为本地存储保存在调用页面中,

 例如:在您的调用JavaScript文件中,使用:
window.localStorage .setItem('param','abc');

现在,在您的调用文件中,访问本地存储并删除它
param abc = window.localStorage.getItem('param');

window.localStorage.removeItem('param');

希望有帮助。


In a PhoneGap app, we can setup the starting page using the following code.

self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index.html";

But it won't work if I want to pass parameters to that page.

self.viewController.startPage = @"index.html?parameter=abc";

It will cause an NSURLErrorRedirectToNonExistentLocation error.

Is there an easy way to pass parameters to a local page?

解决方案

In phonegap apps, you cannot call local pages by passing parameters to them because the system searches for files with exactly the same name as you pass. It doesn't treat the parameters as query string.

Ex: when you say "index.html?param=abc", instead of calling page index.html with a
parameter called param having value abc. It calls the page "index.html?param=abc"
which doesn't exist in the system. Hence, the error.

The best method to solve the issue is to save your parameters as local storages in the calling page, consume them in your next page and destroy them.

Ex: In your calling JavaScript file, use:
window.localStorage.setItem('param', 'abc');

Now, in your called file, access the local storage and delete it
param abc = window.localStorage.getItem('param');

window.localStorage.removeItem('param');

Hope that helps.

这篇关于如何将参数传递到PhoneGap应用程序中的本地页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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