javascript 从phonegap中的javascript重定向到本地html页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7643868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:47:18  来源:igfitidea点击:

Redirecting to local html page from javascript in phonegap

javascripthtmlcordova

提问by AndroGeek

I am working on phonegap application. I am trying to login and on click of the submit button in the Login.html i should be redirected to a local html file.

我正在开发 phonegap 应用程序。我正在尝试登录并单击 Login.html 中的提交按钮,我应该被重定向到本地 html 文件。

Login.html

登录.html

<tr>
    <td>&nbsp;</td>
    <td>
        <input type="submit" class="submitbtn" name="submit"
            id="submit" value="Login" onclick="loginCheck()">
    </td>
</tr>

loginValidation.js

登录验证.js

if (validCustomer == true) {

    alert("valid customer........");
    document.location.href("file:///android_asset/www/Category.html"); 

But document.location.hrefor window.location/window.opendoesn't work. Can anybody help on this issue? If i use window.open and run the application in emulator it works fine but not in the device.

但是document.location.hrefwindow.location/window.open不起作用。有人可以帮助解决这个问题吗?如果我使用 window.open 并在模拟器中运行该应用程序,它可以正常工作,但不能在设备中运行。

回答by hemant.patel

you can try this

你可以试试这个

window.open("mainpage.html",'_self');

this will open page in current window so that current window page data get flush and new page data will render in same window page dom.

这将在当前窗口中打开页面,以便当前窗口页面数据刷新,新页面数据将在同一窗口页面 dom 中呈现。

回答by Dmitry F

try using relative path, this should work:

尝试使用相对路径,这应该有效:

window.location="Category.html";

回答by user3164651

Try this

试试这个

window.location.replace = "Category.html";

回答by Suhas

window.location.href = 'Category.html';