【问题标题】:Rediection not working from file system in emulator重定向无法从模拟器中的文件系统工作
【发布时间】:2014-11-20 02:14:20
【问题描述】:

我是 Phonegap 的新手,所以请帮助我摆脱这个问题。

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

a href='#' onClick='test();' id="button">按钮1

函数测试()

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

 }

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

但是当我重定向到 www.google.com 时它工作正常。

函数测试()

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

 }

这是重定向到谷歌页面。

请帮助我。在此先感谢

【问题讨论】:

  • 您是否尝试从根目录访问?在这种情况下window.location="../home/swift-03/phonegapexamples/MySmartCity/www/List.html"@Ashok kumar
  • 感谢您的回复。是的,我从 root 尝试过,但按钮没有响应。我需要使用我的 IP 地址吗?@Arty

标签: javascript html cordova android-emulator


【解决方案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

【讨论】:

  • @Atry ,感谢重播,调用和被调用文件都在同一个目录中。但它仍然显示找不到文件
  • 也许可以试试document.location = "./List.html"; @Ashokkumar
  • ,对不起,这不起作用。在浏览器上它正在运行,但在模拟器中它没有运行
  • 您可以查看question,它可能会有所帮助。 @Ashokkumar
  • 谢谢,我解决了。我没有给出 html 文件的任何路径。只是提到了没有任何路径的文件名。它对我有用。感谢您的支持。@Arty
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-25
  • 1970-01-01
  • 2018-08-07
  • 2018-08-31
  • 1970-01-01
相关资源
最近更新 更多