javascript - Cordova Network Information Plugin: broken? -
this page attempting load backup file scheme if device cannot connect
<!doctype html> <html> <head> <link rel="stylesheet" href="css/about.css"/> </head> <body> <ons-screen> <ons-navigator title = "about"> <ons-page id="page" font-align="center"> </ons-page> </ons-navigator> </ons-screen> </body> <script type="text/javascript"> var page = document.getelementbyid("page"); if(navigator.connection.type != connection.none){ page.innerhtml='<iframe src="http://www.website.com/about/" style="width:100%; height:100%;"></iframe>'; }else{ page.innerhtml='<iframe src="aboutbackup.html" style="width:100%; height:100%;"></iframe>'; } </script> </html> i installed plugin using github instructions (https://github.com/apache/cordova-plugin-network-information/blob/master/doc/index.md)
i can't figure out why, uncaught typeerror: cannot read property 'type' of undefined on line 22 check connection type.
you need add together cordova.js in file.
<script type="text/javascript" src="cordova.js"></script> then hear device ready function , shot goal
<script> document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { if(navigator.connection.type=='none') { alert("wait i'm offline."); } else { page.innerhtml='<iframe src="aboutbackup.html" style="width:100%; height:100%;"></iframe>'; } } </script> anything have after device ready function fired. , without cordova.js cordova plugins won't work.
javascript cordova phonegap-plugins
No comments:
Post a Comment