scarlex
scarlex
  • 发布:2015-03-20 12:52
  • 更新:2015-03-26 13:12
  • 阅读:2900

新版的 mui 点回退键不会关闭 webview ?

分类:MUI
mui

这里指的后退是指 header 左边的后退,而不是系统的后退键。

以前的版本点击后退之后还是会把 webview 关掉的,但今天升级之后,我在 ```javascript
chrome://inspect/#devices

2015-03-20 12:52 负责人:无 分享
已邀请:
DCloud_UNI_CHB

DCloud_UNI_CHB

hello mui使用模板机制,会默认预加载几个页面,因此从chrome://inspect/#devices看webview的话,至少应该存在如下几个webview:

  • index.html
    list.html
    index-menu.html
    template.html
    template_pullrefresh.html
    pullrefresh.html

参考:http://ask.dcloud.net.cn/article/106

scarlex

scarlex (作者)

@DCloud_MUI_CHB
不是hello-mui,而是我自己写的 app,没做过任何预加载之类的。

假设我有一个页面是双webview模式来实现上下拉刷新的,叫 test-header.html 和 test-body.html。
我在另一个页面 (aaa.html) 中打开 test-header.html 时,这个 test-header.html 里面会把 test-body 这个 webview append 到 test-header 这个webview 中形成双 webview。

当我点后退的时候,这两个webview都没有关闭,只是隐藏了。然后我再进入这个页面,又会新建多两个 webview,再后退再进入,又多两个新的 webview。这样重复多几遍,chrome://inspect/#devices 里面看到的就是 2 x N + 1个 webview,那 1 个 webview 是 aaa.html。

mui 升级前没遇到过这个情况,每次点后退都是正常关闭掉 webview 的,升级后就多出了好多个 webview 出来。

DCloud_UNI_CHB

DCloud_UNI_CHB

贴一下如下两处代码:

  • aaa.html中打开test-header.html的代码;
    test-header.html append test-body的代码
scarlex

scarlex (作者)

@DCloud_MUI_CHB

aaa.html 打开 test-header 的代码:

document.getElementById('history').addEventListener('tap', function (e) {  
    mui.openWindow({  
        url: './views/history-header.html',  
        id: 'history-header'  
    });  
});

test-header append test-body 的代码:


var header = plus.webview.currentWebview();  
var body = plus.webview.create('./history-body.html', 'history-body', {top: '48px', bottom: '0px'});  

// 用了 http://fgnass.github.io/spin.js/ 来生成菊花  
var spinnerOptions = {  
    lines: 13, // The number of lines to draw  
    length: 20, // The length of each line  
    width: 10, // The line thickness  
    radius: 30, // The radius of the inner circle  
    corners: 1, // Corner roundness (0..1)  
    rotate: 0, // The rotation offset  
    direction: 1, // 1: clockwise, -1: counterclockwise  
    color: '#000', // #rgb or #rrggbb or array of colors  
    speed: 1, // Rounds per second  
    trail: 60, // Afterglow percentage  
    shadow: false, // Whether to render a shadow  
    hwaccel: false, // Whether to use hardware acceleration  
    className: 'spinner', // The CSS class to assign to the spinner  
    zIndex: 2e9, // The z-index (defaults to 2000000000)  
    top: '50%', // Top position relative to parent  
    left: '50%' // Left position relative to parent  
};  

var _body = document.body;  
var spinner = new Spinner(spinnerOptions).spin();  

body.onloading = function () {  
    _body.appendChild(spinner.el);  
};  

body.onloaded = function () {  
    try {  
        _body.removeChild(spinner.el);  
    } catch (e) {  

    }  

};  

header.append(body);
DCloud_UNI_FXY

DCloud_UNI_FXY

系统的后退键有没有问题?

scarlex

scarlex (作者)

@DCloud_MUI_FXY
点两下系统的后退键就直接退出应用了

DCloud_UNI_FXY

DCloud_UNI_FXY

你自己没额外处理后退的逻辑把。如果没有的话。可以发一个测试工程给我

scarlex

scarlex (作者)

@DCloud_MUI_FXY
额外设置逻辑不是直接覆盖 mui.back 么?

我有试过覆盖它的

    mui.back = function () {  
        // 其他额外工作  
        plus.webview.currentWebview().close();  
    };

不过这样也是按两次系统的后退键就会退出应用,难道设置不对?

DCloud_UNI_FXY

DCloud_UNI_FXY

把你自己处理的back都去掉。再测试

该问题目前已经被锁定, 无法添加新回复