如何将参数传递到PhoneGap应用程序中的本地页面?

Wei*_*Liu 2 parameters ios cordova

在PhoneGap应用程序中,我们可以使用以下代码设置起始页面.

self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index.html";
Run Code Online (Sandbox Code Playgroud)

但是,如果我想将参数传递给该页面,它将无法工作.

self.viewController.startPage = @"index.html?parameter=abc";
Run Code Online (Sandbox Code Playgroud)

它会导致NSURLErrorRedirectToNonExistentLocation错误.

有没有简单的方法将参数传递给本地页面?

SHA*_*ANK 6

在phonegap应用程序中,您无法通过向其传递参数来调用本地页面,因为系统会搜索与您传递的名称完全相同的文件.它不会将参数视为查询字符串.

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.
Run Code Online (Sandbox Code Playgroud)

解决此问题的最佳方法是将参数保存为调用页面中的本地存储,在下一页中使用它们并销毁它们.

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');
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.