简体   繁体   English

允许在 Android webview 中导航

[英]Allow navigation in Android webview

I'm creating an application where I'm opening a website inside a webview.我正在创建一个应用程序,我在 webview 中打开一个网站。

So the website is all about booking a kind of service.所以这个网站就是关于预订一种服务。 And there's a few steps in the website.网站上有几个步骤。

First the user can choose what kind of service to book, and then the user clicks on the button "Continue".首先用户可以选择预订什么样的服务,然后用户点击“继续”按钮。 But the problem is, when the user clicks on the button the website just getting relaoded, which means, we're not getting navigated to the next step.但问题是,当用户点击按钮时,网站只是重新加载,这意味着我们没有被导航到下一步。

Is there anything I have to change in the code?代码中有什么我需要改变的吗?

So I would like to navigate to the next "step" in the webview once the user clicks on a button.因此,一旦用户单击按钮,我想导航到 web 视图中的下一个“步骤”。 But instead the website is just getting relaoded and all the data is "lost".但相反,该网站只是重新加载,所有数据都“丢失”了。

    public void webView(){
    WebView webview = view.findViewById(R.id.service_webview);

    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);

    webview.loadUrl("https://www.HIDDENURL.com/book/choose-service");
}

I'm allowing Javascript.我允许使用 Javascript。 But is there anything else I have to add to accomplish this?但是我还需要添加什么来实现这一点吗?

NOTE!笔记! I'm not owning the website, so I cannot change anything.我不拥有该网站,因此我无法更改任何内容。 NOTE!笔记! When I click on "continue" the other page is "opening" for a milisecond, then automatically closes and starts over.当我点击“继续”时,另一个页面会“打开”一毫秒,然后自动关闭并重新开始。

The issue was with the Ajax call in your website which will load a particular section in the page, you will have to enable DomStorage also to achieve this.问题在于您网站中的 Ajax 调用将加载页面中的特定部分,您还必须启用 DomStorage 来实现此目的。

 public void webView(){
        WebView webview = view.findViewById(R.id.service_webview);

        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        webview.loadUrl("https://www.HIDDENURL.com/book/choose-service");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM