HTML 5中的存储及离线应用(五)
2012-08-22 10:31
281 查看
最后咱们再来看看离线应用:
离线应用需要有一个缓存的Manifest文件:
文件类型(MIME-type)是:text/cache-manifest,这份工作应该在web server上进行;
文件以“CACHE MANIFEST”开头;
文件中有如下节:CACHE,表示缓存的文件,这个是默认节,如果未指明节的情况下默认是CACHE;NETWORK,表示不能被缓存的文件;FALLBACK表示离线时用来替换在线时的文件;
CACHE MANIFEST
CACHE:
exp-calif-logo-offline.gif
sessionStorage.html
../CSS/main.css
../Javascript/bwH5LS.js
FALLBACK:
exp-calif-logo.gif exp-calif-logo-offline.gif
上面就是一个测试的manifest文件。
测试的html文件如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- 测试的manifest文件 -->
<html xmlns="http://www.w3.org/1999/xhtml" manifest="sessionStorage.manifest">
<!--
sessionStorage.html by Bill Weinman
<http://bw.org/contact/>
created 2011-04-16
Copyright (c) 2011 The BearHeart Group, LLC
This file may be used for personal educational purposes as needed.
Use for other purposes is granted provided that this notice is
retained and any changes made are clearly indicated as such.
-->
<head>
<title>
sessionStorage example
</title>
<link rel="stylesheet" type="text/css" href="../CSS/main.css">
<script language="javascript" src="../Javascript/bwH5LS.js"></script>
<script language="javascript">
var t = new bwTable();
var db = getSessionStorage() || dispError('Session Storage not supported.');
function getSessionStorage() {
try {
if( !! window.sessionStorage ) return window.sessionStorage;
} catch(e) {
return undefined;
}
}
function dispResults() {
if(errorMessage) {
element('results').innerHTML = errorMessage;
return;
}
var t = new bwTable();
t.addRow( ['traveler', db.getItem('traveler')] );
t.addRow( ['destination', db.getItem('destination')] );
t.addRow( ['transportation', db.getItem('transportation')] );
element('results').innerHTML = t.getTableHTML();
element('travelForm').elements['traveler'].focus();
element('travelForm').elements['traveler'].select();
}
function dbGo() {
if(errorMessage) return;
var f = element('travelForm');
db.setItem('traveler', f.elements['traveler'].value);
db.setItem('destination', f.elements['destination'].value);
db.setItem('transportation', f.elements['transportation'].value);
dispResults();
}
function dbClear() {
if(errorMessage) return;
db.clear();
dispResults();
}
function initDisp() {
dispResults();
}
window.onload = function() {
initDisp();
}
</script>
</head>
<body>
<div id="content">
<img src="exp-calif-logo.gif" style="float: left; margin-right: 10px"/>
<h1>
sessionStorage example
</h1>
<div id="form">
<form id="travelForm">
<table class="form">
<tr><td class="label"> Traveler </td><td> <input type="text" name="traveler" /> </td></tr>
<tr><td class="label"> Destination </td><td> <input type="text" name="destination" /> </td></tr>
<tr><td class="label"> Transportation </td><td> <input type="text" name="transportation" /> </td></tr>
<tr><td colspan="2" class="button">
<input id="formSubmit" type="button" value="Clear" onClick="javascript:dbClear()" />
<input id="formSubmit" type="button" value="Go" onClick="javascript:dbGo()" />
</td></tr>
</table>
<input id="inputAction" type="hidden" name="action" value="add" />
<input id="inputKey" type="hidden" name="key" value="0" />
</form>
</div>
<div id="results">
<!-- results show here -->
</div>
</div>
</body>
</html>
离线应用需要有一个缓存的Manifest文件:
文件类型(MIME-type)是:text/cache-manifest,这份工作应该在web server上进行;
文件以“CACHE MANIFEST”开头;
文件中有如下节:CACHE,表示缓存的文件,这个是默认节,如果未指明节的情况下默认是CACHE;NETWORK,表示不能被缓存的文件;FALLBACK表示离线时用来替换在线时的文件;
CACHE MANIFEST
CACHE:
exp-calif-logo-offline.gif
sessionStorage.html
../CSS/main.css
../Javascript/bwH5LS.js
FALLBACK:
exp-calif-logo.gif exp-calif-logo-offline.gif
上面就是一个测试的manifest文件。
测试的html文件如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- 测试的manifest文件 -->
<html xmlns="http://www.w3.org/1999/xhtml" manifest="sessionStorage.manifest">
<!--
sessionStorage.html by Bill Weinman
<http://bw.org/contact/>
created 2011-04-16
Copyright (c) 2011 The BearHeart Group, LLC
This file may be used for personal educational purposes as needed.
Use for other purposes is granted provided that this notice is
retained and any changes made are clearly indicated as such.
-->
<head>
<title>
sessionStorage example
</title>
<link rel="stylesheet" type="text/css" href="../CSS/main.css">
<script language="javascript" src="../Javascript/bwH5LS.js"></script>
<script language="javascript">
var t = new bwTable();
var db = getSessionStorage() || dispError('Session Storage not supported.');
function getSessionStorage() {
try {
if( !! window.sessionStorage ) return window.sessionStorage;
} catch(e) {
return undefined;
}
}
function dispResults() {
if(errorMessage) {
element('results').innerHTML = errorMessage;
return;
}
var t = new bwTable();
t.addRow( ['traveler', db.getItem('traveler')] );
t.addRow( ['destination', db.getItem('destination')] );
t.addRow( ['transportation', db.getItem('transportation')] );
element('results').innerHTML = t.getTableHTML();
element('travelForm').elements['traveler'].focus();
element('travelForm').elements['traveler'].select();
}
function dbGo() {
if(errorMessage) return;
var f = element('travelForm');
db.setItem('traveler', f.elements['traveler'].value);
db.setItem('destination', f.elements['destination'].value);
db.setItem('transportation', f.elements['transportation'].value);
dispResults();
}
function dbClear() {
if(errorMessage) return;
db.clear();
dispResults();
}
function initDisp() {
dispResults();
}
window.onload = function() {
initDisp();
}
</script>
</head>
<body>
<div id="content">
<img src="exp-calif-logo.gif" style="float: left; margin-right: 10px"/>
<h1>
sessionStorage example
</h1>
<div id="form">
<form id="travelForm">
<table class="form">
<tr><td class="label"> Traveler </td><td> <input type="text" name="traveler" /> </td></tr>
<tr><td class="label"> Destination </td><td> <input type="text" name="destination" /> </td></tr>
<tr><td class="label"> Transportation </td><td> <input type="text" name="transportation" /> </td></tr>
<tr><td colspan="2" class="button">
<input id="formSubmit" type="button" value="Clear" onClick="javascript:dbClear()" />
<input id="formSubmit" type="button" value="Go" onClick="javascript:dbGo()" />
</td></tr>
</table>
<input id="inputAction" type="hidden" name="action" value="add" />
<input id="inputKey" type="hidden" name="key" value="0" />
</form>
</div>
<div id="results">
<!-- results show here -->
</div>
</div>
</body>
</html>
相关文章推荐
- HTML 5中的存储及离线应用(一)
- HTML 5中的存储及离线应用(二)
- HTML 5中的存储及离线应用(三)
- HTML 5中的存储及离线应用(四)
- js023-离线应用与客户端存储
- 离线iOS应用的HTML 5制作指南
- HTML5本地存储之Web SQL+LocalStorage+ApplicationCache以及indexed+LocalStorage+ApplicationCache构建的离线应用实例代码
- 国外海量数据离线存储产品应用
- HTML 5 Web 存储 与 应用缓存(清晰明了)
- 应用程序存储和离线Web应用
- H5中离线应用存储-------------------明日完成
- HTML5五种客户端离线存储方案
- HTML 5 Web 存储 与 应用缓存
- html离线存储之indexdDB 关于Cannot read property 'transaction' of undefined的问题(二)
- html本地存储方式实现的五线谱在线识谱练习应用
- JS高级程序设计23-离线应用与客户端存储
- [分享黑科技]纯js突破localstorage存储上线,远程抓取图片,并转码base64保存本地,最终实现整个网站所有静态资源离线到用户手机效果却不依赖浏览器的缓存机制,单页应用最新黑科技
- 在Android中使用HTML5本地存储,地理位置,离线应用
- HTML5+规范:Storage(管理应用本地数据存储区)
- 【JavaScript】离线应用与客户端存储