create_webview_home.html(主頁)
<!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <link href="css/mui.min.css" rel="stylesheet" /> </head> <body> <button id="button1" class="mui-btn mui-badge-purple">打開子頁</button> <script src="js/mui.min.js"></script> <script type="text/javascript"> mui.init(); document.getElementById("button1").addEventListener('tap', function() { mui.plusReady(function() { var nwating = plus.nativeUI.showWaiting(); //顯示原生等待框 var webview_sub = plus.webview.create( 'create_webview_sub.html', 'create_webview_sub', {}, { name: 'davis' }); //後臺建立webview並打開頁面 webview_sub.addEventListener('loaded', function() { nwating.close(); //關閉等待框 webview_sub.show('slide-in-right', 150); //把新的webview窗口顯示出來 }, false); }); }) </script> </body> </html>
create_webview_sub.html(新頁面)
<!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <link href="css/mui.min.css" rel="stylesheet" /> </head> <body> <div id="div1"></div> <script src="js/mui.min.js"></script> <script type="text/javascript"> mui.init(); mui.plusReady(function () { document.getElementById("div1").innerText='hi,'+plus.webview.currentWebview().name; }) </script> </body> </html>