第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

setTimeout的機(jī)制引起的bug

setTimeout的機(jī)制引起的bug

慕田峪7331174 2018-09-05 14:15:16
瀏覽器打開了2個(gè)標(biāo)簽頁,其中一個(gè)標(biāo)簽頁A中有如下代碼:`    var time = 0;    var i = 0;    var t = 0;    function test(){         i++;         setTimeout(function(){             $('body').append('-'+i);             test();         },100);     }     test();    `如果我一直停留在這個(gè)頁面上,程序沒有任何問題,會(huì)不斷的在頁面上打印遞增的數(shù)字 ,但是當(dāng)我點(diǎn)擊另一個(gè)標(biāo)簽頁B時(shí),標(biāo)簽頁A中的代碼會(huì)停止執(zhí)行,直到我重新切換到標(biāo)簽頁A時(shí),代碼又會(huì)繼續(xù)執(zhí)行。這個(gè)問題不知道要怎么解決,求大神幫忙感激不盡!PS.經(jīng)過測試,發(fā)現(xiàn)這個(gè)問題只有在chrome和firefox才會(huì)出現(xiàn),IE正常。再PS.上面說的停止執(zhí)行是我的視覺誤判,真實(shí)原因如下:On the Chromium blog, Google said: In the forthcoming Chrome 11 release, we plan to reduce CPU consumption even for pages that are using setTimeout and setInterval. For background tabs, we intend to run each independent timer no more than once per second. This change has already been implemented in the Chrome dev channel and canary builds.解決辦法:使用webworker(兼容性不夠好)或者使用這個(gè)補(bǔ)丁 https://github.com/turuslan/H...
查看完整描述

1 回答

?
鴻蒙傳說

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

參考這里:傳送門

原文:

Convert background page to event page

Follow this checklist to convert your extension's (persistent) background page to an event page.

Add "persistent": false to your manifest as shown above.
If your extension uses window.setTimeout() or window.setInterval(), switch to using the alarms API instead. DOM-based timers won't be honored if the event page shuts down.
Similarly, other asynchronous HTML5 APIs like notifications and geolocation will not complete if the event page shuts down. Instead, use equivalent extension APIs, like notifications.
If your extension uses, extension.getBackgroundPage, switch to runtime.getBackgroundPage instead. The newer method is asynchronous so that it can start the event page if necessary before returning it.

英語不是特別好,就不做中間翻譯了。


查看完整回答
反對(duì) 回復(fù) 2018-10-29
  • 1 回答
  • 0 關(guān)注
  • 763 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)