重定向无法在模拟器中的文件系统中运行

时间:2014-09-25 10:30:59

标签: javascript html cordova android-emulator

我是Phonegap的新手,所以请帮我解决这个问题。

在我的应用程序中,我必须在单击button1时重定向到List.html文件,我写了这样的代码,

a href ='#'的onClick ='测试();' ID ="按钮">按钮1

功能测试()

 {
       window.location="/home/swift-03/phonegapexamples/MySmartCity/www/List.html";

 }

但是在模拟器上运行时显示文件未找到。我是否应该使用本地IP地址重定向到本地目录中的List.html。

但是当我重定向到www.google.com时,它运行正常。

功能测试()

 {
       window.location="www.google.com";

 }

这是重定向到谷歌页面。

请帮助我。提前谢谢

1 个答案:

答案 0 :(得分:1)

假设显示button1的原始HTML位于同一文件目录中,您必须这样做:

HTML:

<body>
 <input type="button" href='#' onClick='test();' id="button" value="button1" ></input>
</body>

的Javascript:

function test(){ /* Provideed master.html is in the same directory as the html that has button1*/ window.location=" ./master.html"; }

我希望这是有道理的。如果要访问上面的两个目录,则必须使用../master.html,但在这种情况下,如果文件位于同一目录中,则必须执行./master.html