国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

正在使用electron和node.js做桌面應用,需要實時監聽是否有網絡連接,node或者electron是否可以做到

瀏覽:166日期:2024-07-29 17:01:19

問題描述

正在使用electron和node.js做桌面應用,需要實時監聽是否有網絡連接,node或者electron是否可以做到

如標題,實時監聽網絡情況,如果沒有網絡情況就會顯示脫機,請問node或者electron是否可以做到?求教

問題解答

回答1:

試試navigator.onLine,不需要node.js不需要electron,普通網頁都能判斷是否有網絡

回答2:

官方文檔:http://electron.atom.io/docs/...

回答3:

function isOnline(user_callback){ /** * Show a warning to the user. * You can retry in the dialog until a internet connection * is active. */ var message = function(){const {dialog} = require(’electron’).remote;return dialog.showMessageBox({ title:'There’s no internet', message:'No internet available, do you want to try again?', type:’warning’, buttons:['Try again please','I don’t want to work anyway'], defaultId: 0},function(index){ // if clicked 'Try again please' if(index == 0){execute(); }}) }; var execute = function(){if(navigator.onLine){ // Execute action if internet available. user_callback();}else{ // Show warning to user // And 'retry' to connect message();} }; // Verify for first time execute();}// Use it, the alert('Hello world'); will be executed only if there’s an active internet connection.isOnline(function(){ alert('Hello world !');});

you can check out this blog for details.

回答4:

監聽navigator.onLine可以實現,感謝兩位的幫助

window.addEventListener('offline', function(e) { alert('offline')})window.addEventListener('online', function(e) { alert('online')})

主站蜘蛛池模板: 普定县| 营山县| 龙游县| 西乡县| 濮阳市| 安徽省| 从江县| 增城市| 高尔夫| 铜川市| 万盛区| 扶风县| 嘉兴市| 廊坊市| 察隅县| 安宁市| 龙游县| 高阳县| 钟山县| 元氏县| 德昌县| 泸西县| 东至县| 六安市| 滦平县| 武功县| 剑川县| 常山县| 泰顺县| 盐池县| 长泰县| 泽库县| 广宁县| 龙门县| 邵东县| 鄂托克旗| 惠东县| 溆浦县| 肥乡县| 五峰| 疏附县|