安家
安家
  • 发布:2016-08-10 17:56
  • 更新:2016-08-10 18:04
  • 阅读:1444

父窗口不变,子窗口跳转问题求教

分类:HTML5+

首页通过

            mui.init({  
                swipeBack: false,  
                subpages: [{  
                    id: 'main',  
                    url: 'main.html',  
                    styles: {  
                        top: '45px',  
                        bottom: 0  
                    }  
                }]  
            });

创建了子页面
在子页面通过href跳转(类似html的iframe),父页面不变
但是在子页面通过mui.openWindow和plus.webview.open 打开新页面,会直接打开新的窗口(不再留在父页面下)
只能通过子页面.loadURL(新地址)的方式跳转么?(history.back()不起作用)

2016-08-10 17:56 4 条评论 负责人:无 分享
已邀请:
赵梦欢

赵梦欢 - 专注前端,乐于分享!

  • 安家 (作者)

    非常感谢,但是只适合一层调用(既a-b,b后退返回a),不适合a-b-c-d 从d history.back()直接就返回list.html了

    2016-08-10 18:40

  • 安家 (作者)

    公共js方法


    var template;

    var historyUrls;

    var subWebview;

    var aniShow="slide-in-right";

    mui.plusReady(function () {

    template= plus.webview.getWebviewById(plus.runtime.appid);

    // 预加载公用子页面

    subWebview = plus.webview.getWebviewById("sub_template")||mui.preload({

    url:'',

    id:'sub_template',

    styles:{

    top: '45px',

    bottom: '0px'

    }

    });

    // 将子页面填充到父页面

    template.append(subWebview);


    mui.back = function() {  
    historyUrls=JSON.parse(localStorage.historyUrls||"[]");
    historyUrls.pop();
    localStorage.historyUrls=JSON.stringify(historyUrls);
    var href=historyUrls.pop();
    if(href) {
    loadWindow(href,true);
    }
    }

    })


    var loadWindow=function(href,isBack){

    isBack=isBack||false;

    subWebview.hide("auto");

    href=plus.io.convertLocalFileSystemURL(href);

    // 加载子页面地址

    if (plus.io.convertLocalFileSystemURL(subWebview.getURL())==href) {

    setTimeout(function(){

    subWebview.show(aniShow);

    },150)

    } else{

    subWebview.loadURL(href);

    if(!isBack){

    historyUrls=JSON.parse(localStorage.historyUrls||"[]");

    historyUrls.push(href);

    localStorage.historyUrls=JSON.stringify(historyUrls);

    }

    // 子页面加载完成显示

    subWebview.addEventListener('loaded', function() {

    subWebview.show(aniShow,150)

    });

    }

    }

    主页面index.html

    <script type="text/javascript">

    mui.init();

    mui.plusReady(function () {

    localStorage.historyUrls="[]";

    loadWindow(“demo.html");

    })

    </script>

    子页面demo.html

    <script type="text/javascript">

    mui.init();

    mui.plusReady(function () {

    mui(".mui-table-view").on('tap','li a',function(){

    loadWindow(this.href);

    })

    })

    </script>

    2016-08-11 13:43

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