【问题标题】:Cordova InAppBrowser clear search historyCordova InAppBrowser 清除搜索历史
【发布时间】:2019-02-01 13:03:09
【问题描述】:

我正在创建一个应用程序,您可以在其中打开 google 以找到答案的解决方案:

 ref = cordova.InAppBrowser.open('https://google.nl/', '_blank', 'clearsessioncache=yes, clearcache=yes');

尽管我发送了属性 clearsessioncache=yes, clearcache=yes 并且我没有登录 Google,但当我进入搜索框时它一直显示以前的搜索结果。

有人可以解释为什么历史记录不断显示在“推荐”网站中吗?如果有任何方法可以防止这种情况发生。

【问题讨论】:

    标签: cordova cordova-plugins inappbrowser


    【解决方案1】:

    自己找到了答案。希望它可以帮助其他有同样问题的人:

    Google 搜索历史存储在 localStorage 中。所以在显示 InAppBrowser 之前清除 localStorage 可以解决问题:

    this.ref = cordova.InAppBrowser.open('https://www.google.nl/', '_blank', 'clearsessioncache=yes,clearcache=yes,closebuttoncaption=Terug,closebuttoncolor=#4286f4,hideurlbar=yes,hidden=yes');
    this.ref.addEventListener('loadstop', () => {
        var init = false
        this.ref.addEventListener('loadstop', () => {
            if (!init) {
                // clear localStorage to clear Google search history
                this.ref.executeScript({
                    code: `
            (function() { 
                localStorage.clear();
                return true;
             })()` }, _ => {
                        // cache is cleared. Now we can show the browser.
                        this.ref.show();
                        init = true;
                    });
            }
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-12
      • 2022-08-03
      • 2012-12-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      相关资源
      最近更新 更多