Skip to Content
MOBILE WEB程式設計--第二版
book

MOBILE WEB程式設計--第二版

by Maximiliano Firtman
December 2013
Intermediate to advanced
752 pages
16h
Chinese
GoTop Information, Inc.
Content preview from MOBILE WEB程式設計--第二版
438
|
第十二章
var detectWakeFromSleep_ = function() {
var now = new Date().getTime();
var delta = now - this.lastTick_;
if (delta > THRESHOLD) {
// App 可能在睡著後醒來了。
notifyWakeFromSleep(delta/1000);
}
lastTick_ = now;
};
notifyWakeFromSleep()
方法中,你可以根據收到的參數(告訴你從上次啟動狀態算起
經過多少秒數)來決定要做什麼事情。在 delta 時間是 10 秒或 1 天(86,400 秒)的情況
下,你要做的事情可能會不一樣。例如,在一段很長的 delta 之後,你或許想要顯示一
個警告,或者,如果新結果是由 Ajax 讀取時,顯示載入動畫。
在這個情況之下,我們可能沒有喚醒網頁的機會:如果設備已經耗盡記憶
體,而且我們的網頁處於幕後,瀏覽器可能會刪除網頁狀態來釋放記憶體,
所以當使用者回來時,我們的網頁會以一個新的對話,透過 URL 載入。
請記得,由休眠醒來之後,文字與指令碼處於同樣的狀態(包括它們的 HTML 內容與
JavaScript 變數),因為它們是進入睡眠,除非作業系統或瀏覽器決定完全將它們從記憶
體移除,在這個情況下,網站將會被重新載入。
幕後標籤通知技巧
雖然從使用者的角度來看,這或許是個惱人的行為,但舊的 HTML 機制可讓我們定義一
個中繼標籤,每隔
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

成為卓越程式設計師的38項必修法則

成為卓越程式設計師的38項必修法則

Pete Goodliffe
精實企業|高績效組織如何達成創新規模化

精實企業|高績效組織如何達成創新規模化

Jez Humble, Joanne Molesky, Barry O'Reilly

Publisher Resources

ISBN: 9789862769522